def _init_script(self, args): """Place a generic init script on the system. :param args: ``dict`` """ for script in args: name = script['program'] script['bin'] = name script['exec'] = ' '.join(['${DAEMON}', script.get('options', '')]) script['pid_file'] = '/var/run/%s.pid' % name ssd = [ '--start', '--background', '--make-pidfile', '--pidfile ${PID_FILE}' ] if 'chuid' in script: ssd.append('--chuid %s' % script['chuid']) if 'chdir' in script: ssd.append('--chdir %s' % script['chdir']) ssd.append('--exec %(exec)s') script['start_stop_daemon'] = ' '.join(ssd) % script file_create = { 'path': script['init_path'], 'name': script['name'], 'contents': basic_init.INIT_SCRIPT % script, 'group': 'root', 'user': '******', 'mode': '0755' } self._file_create(args=[file_create]) distro = package_installer.distro_check() if distro in ['apt']: commands = ['update-rc.d %(name)s defaults' % script] elif distro in ['yum', 'zypper']: commands = ['chkconfig on %(name)s' % script] else: raise genastack.CantContinue('Unkown Init System...') self.__execute_command(commands=commands)
def test_distro_check_suse(self): self.linux_distribution.return_value = ['suse'] self.assertEqual(package_installer.distro_check(), 'zypper')
def test_distro_check_centos(self): self.linux_distribution.return_value = ['centos'] self.assertEqual(package_installer.distro_check(), 'yum')
def test_distro_check_ubuntu(self): self.linux_distribution.return_value = ['ubuntu'] self.assertEqual(package_installer.distro_check(), 'apt')