def generate(self, overwrite): """Generates service files. This exposes several comforts. `self.files` is a list into which all generated file paths will be appended. It is later returned by `generate` to be consumed by any program that wants to do something with it. `self.templates` is the directory in which all templates are stored. New init system implementations can use this to easily pull template files. `self.template_prefix` is a prefix for all template files. Since all template files should be named `<INIT_SYS_NAME>_<INIT_SYS_VERSION>*`, this will basically just provide the prefix before the * for you to use. `self.generate_into_prefix` is a prefix for the path into which files will be generated. This is NOT the destination path for the file when deploying the service. `self.overwrite` automatically deals with overwriting files so that the developer doesn't have to address this. It is provided by the API or by the CLI and propagated. """ self.files = [] tmp = utils.get_tmp_dir(self.init_sys, self.name) self.templates = os.path.join(os.path.dirname(__file__), 'templates') self.template_prefix = '_'.join([self.init_sys, self.init_sys_ver]) self.generate_into_prefix = os.path.join(tmp, self.name) self.overwrite = overwrite
def test_sysv(self): self._test_generate("sysv") self.assertIn("program={0}".format(self.cmd), self.content) self.assertIn('args="{0}"'.format(self.args), self.content) self.assertIn('nice -n "$nice"', self.content) self.assertIn("ulimit -d 10 -m 20", self.content) env_vars_file = os.path.join(utils.get_tmp_dir("sysv", self.service), self.service + ".defaults") with open(env_vars_file) as vars_file: content = vars_file.read() self.assertIn('nice="5"', content)
def test_sysv(self): self._test_generate('sysv') self.assertIn('program={0}'.format(self.cmd), self.content) self.assertIn('args="{0}"'.format(self.args), self.content) self.assertIn('nice -n "$nice"', self.content) self.assertIn('ulimit -d 10 -m 20', self.content) env_vars_file = os.path.join(utils.get_tmp_dir('sysv', self.service), self.service + '.defaults') with open(env_vars_file) as vars_file: content = vars_file.read() self.assertIn('nice="5"', content)
def test_systemd(self): self._test_generate("systemd") self.assertIn(self.cmd + " " + self.args, self.content) self.assertIn("LimitNICE=5", self.content) self.assertIn("LimitCORE=10", self.content) self.assertIn("LimitRSS=20", self.content) env_vars_file = os.path.join(utils.get_tmp_dir("systemd", self.service), self.service) with open(env_vars_file) as vars_file: content = vars_file.read() self.assertIn("KEY1=VALUE1", content)
def test_systemd(self): self._test_generate('systemd') self.assertIn(self.cmd + ' ' + self.args, self.content) self.assertIn('LimitNICE=5', self.content) self.assertIn('LimitCORE=10', self.content) self.assertIn('LimitRSS=20', self.content) env_vars_file = os.path.join( utils.get_tmp_dir('systemd', self.service), self.service) with open(env_vars_file) as vars_file: content = vars_file.read() self.assertIn('KEY1=VALUE1', content)
def _get_file_for_system(self, system): return os.path.join(utils.get_tmp_dir(system, self.service), getattr(self, system))