def create_config(self): # creating the installation script self._logger.debug( 'Rendering configuration script "{0}" from template'.format( self.config_path)) utils.render_template_to_file( template_path='pm/nssm/nssm.conf.template', file_path=self.config_path, queue=self.queue, nssm_path=self.nssm_path, log_level=self.log_level.upper(), log_dir=self.log_dir, workdir=self.workdir, user=self.user, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, max_workers=self.max_workers, virtualenv_path=VIRTUALENV, name=self.name, custom_environment=self._create_env_string(), executable_temp_path=self.executable_temp_path, startup_policy=self.startup_policy, failure_reset_timeout=self.failure_reset_timeout, failure_restart_delay=self.failure_restart_delay, storage_dir=utils.internal.get_storage_directory(self.user), ) self._logger.debug('Rendered configuration script: {0}'.format( self.config_path)) # run the configuration script self._logger.info('Running configuration script') self._runner.run(self.config_path) self._logger.debug('Successfully executed configuration script')
def create_enable_cron_script(self): enable_cron_script = os.path.join( self.workdir, '{0}-enable-cron.sh'.format(self.name)) cron_respawn_path = os.path.join( self.workdir, '{0}-respawn.sh'.format(self.name)) self._logger.debug('Rendering respawn script from template') utils.render_template_to_file( template_path='respawn.sh.template', file_path=cron_respawn_path, start_command=self.start_command(), status_command=self.status_command() ) self._runner.run('chmod +x {0}'.format(cron_respawn_path)) self._logger.debug('Rendering enable cron script from template') utils.render_template_to_file( template_path='crontab/enable.sh.template', file_path=enable_cron_script, cron_respawn_delay=self.cron_respawn_delay, cron_respawn_path=cron_respawn_path, user=self.user, workdir=self.workdir, name=self.name ) self._runner.run('chmod +x {0}'.format(enable_cron_script)) return enable_cron_script
def create_enable_cron_script(self): enable_cron_script = os.path.join( self.workdir, '{0}-enable-cron.sh'.format(self.name)) cron_respawn_path = os.path.join(self.workdir, '{0}-respawn.sh'.format(self.name)) self._logger.debug('Rendering respawn script from template') utils.render_template_to_file(template_path='respawn.sh.template', file_path=cron_respawn_path, start_command=self.start_command(), status_command=self.status_command()) self._runner.run('chmod +x {0}'.format(cron_respawn_path)) self._logger.debug('Rendering enable cron script from template') utils.render_template_to_file( template_path='crontab/enable.sh.template', file_path=enable_cron_script, cron_respawn_delay=self.cron_respawn_delay, cron_respawn_path=cron_respawn_path, user=self.user, workdir=self.workdir, name=self.name) self._runner.run('chmod +x {0}'.format(enable_cron_script)) return enable_cron_script
def create_config(self): # creating the installation script self._logger.info( 'Rendering configuration script "{0}" from template'.format( self.config_path)) utils.render_template_to_file( template_path='pm/nssm/nssm.conf.template', file_path=self.config_path, queue=self.queue, nssm_path=self.nssm_path, log_level=self.log_level.upper(), log_dir=self.log_dir, log_max_bytes=self.log_max_bytes, log_max_history=self.log_max_history, workdir=self.workdir, user=self.user, service_user=self.service_user, service_password=self.service_password, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, max_workers=self.max_workers, virtualenv_path=VIRTUALENV, name=self.name, custom_environment=self._create_env_string(), executable_temp_path=self.executable_temp_path, startup_policy=self.startup_policy, failure_reset_timeout=self.failure_reset_timeout, failure_restart_delay=self.failure_restart_delay, storage_dir=utils.internal.get_storage_directory(self.user), ) self._logger.info('Rendered configuration script: {0}'.format( self.config_path)) # run the configuration script self._logger.info('Running configuration script') try: result = self._runner.run([ 'powershell.exe', '-ExecutionPolicy', 'bypass', '-File', self.config_path, ]) self._logger.info(result.std_out.strip()) self._logger.warning(result.std_err.strip()) except Exception: # Log the exception here, then re-raise it. This is done in order # to ensure that the full exception message is shown. self._logger.exception("Failure encountered while running " "configuration script") raise self._logger.info('Successfully executed configuration script')
def create_disable_cron_script(self): disable_cron_script = os.path.join( self.workdir, '{0}-disable-cron.sh'.format(self.name)) self._logger.debug('Rendering disable cron script from template') utils.render_template_to_file( template_path='crontab/disable.sh.template', file_path=disable_cron_script, name=self.name, workdir=self.workdir) self._runner.run('chmod +x {0}'.format(disable_cron_script)) return disable_cron_script
def _create_config(self): self._logger.debug('Rendering configuration script from template') utils.render_template_to_file( template_path='pm/detach/detach.conf.template', file_path=self.config_path, user=self.user, name=self.name, broker_url=self.broker_url, manager_ip=self.manager_ip, manager_port=self.manager_port, extra_env_path=self.extra_env_path, storage_dir=utils.internal.get_storage_directory(self.user), )
def create_disable_cron_script(self): disable_cron_script = os.path.join( self.workdir, '{0}-disable-cron.sh'.format(self.name)) self._logger.debug('Rendering disable cron script from template') utils.render_template_to_file( template_path='crontab/disable.sh.template', file_path=disable_cron_script, name=self.name, workdir=self.workdir ) self._runner.run('chmod +x {0}'.format(disable_cron_script)) return disable_cron_script
def _create_config(self): self._logger.debug('Rendering configuration script from template') utils.render_template_to_file( template_path='pm/detach/detach.conf.template', file_path=self.config_path, user=self.user, name=self.name, broker_url=self.broker_url, manager_ip=self.manager_ip, manager_port=self.manager_port, extra_env_path=self.extra_env_path, storage_dir=utils.internal.get_storage_directory(self.user), workdir=self.workdir, )
def test_rendered_template_to_file(self): temp = utils.render_template_to_file(template_path=os.path.join( 'pm', 'initd', 'initd.conf.template'), manager_ip='127.0.0.1') with open(temp) as f: rendered = f.read() self.assertTrue('export MANAGEMENT_IP=127.0.0.1' in rendered)
def _create_config(self): self._logger.debug('Rendering configuration script from template') rendered = utils.render_template_to_file( template_path='pm/initd/initd.conf.template', queue=self.queue, workdir=self.workdir, manager_ip=self.manager_ip, manager_port=self.manager_port, broker_url=self.broker_url, user=self.user, min_workers=self.min_workers, max_workers=self.max_workers, includes_path=self.includes_path, virtualenv_path=VIRTUALENV, extra_env_path=self.extra_env_path, name=self.name, storage_dir=utils.internal.get_storage_directory(self.user), log_level=self.log_level, log_file=self.get_logfile(), pid_file=self.pid_file, cron_respawn=str(self.cron_respawn).lower(), enable_cron_script=self.create_enable_cron_script(), disable_cron_script=self.create_disable_cron_script() ) self._runner.run('sudo mkdir -p {0}'.format( os.path.dirname(self.config_path))) self._runner.run('sudo cp {0} {1}'.format(rendered, self.config_path)) self._runner.run('sudo rm {0}'.format(rendered))
def test_rendered_template_to_file(): temp = utils.render_template_to_file(template_path=os.path.join( 'pm', 'initd', 'initd.conf.template'), rest_host=['127.0.0.1']) with open(temp) as f: rendered = f.read() assert 'export REST_HOST="127.0.0.1"' in rendered
def test_rendered_template_to_file(self): temp = utils.render_template_to_file(template_path=os.path.join( 'pm', 'initd', 'initd.conf.template'), rest_host='127.0.0.1') with open(temp) as f: rendered = f.read() self.assertTrue('export REST_HOST=127.0.0.1' in rendered)
def create_config(self): self._logger.debug( 'Rendering configuration script "{0}" from template'.format( self.config_path)) rendered = utils.render_template_to_file( template_path='pm/initd/initd.conf.template', queue=self.queue, workdir=self.workdir, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, broker_url=self.broker_url, user=self.user, min_workers=self.min_workers, max_workers=self.max_workers, virtualenv_path=VIRTUALENV, extra_env_path=self.extra_env_path, name=self.name, storage_dir=utils.internal.get_storage_directory(self.user), log_level=self.log_level, log_file=self.get_logfile(), pid_file=self.pid_file, cron_respawn=str(self.cron_respawn).lower(), enable_cron_script=self.create_enable_cron_script(), disable_cron_script=self.create_disable_cron_script(), cluster_settings_path=self.cluster_settings_path, executable_temp_path=self.executable_temp_path) self._runner.run('sudo mkdir -p {0}'.format( os.path.dirname(self.config_path))) self._runner.run('sudo cp {0} {1}'.format(rendered, self.config_path)) self._runner.run('sudo rm {0}'.format(rendered))
def configure(self): env_string = self._create_env_string() # creating the installation script self._logger.debug('Rendering configuration script from template') utils.render_template_to_file( template_path='pm/nssm/nssm.conf.template', file_path=self.config_path, queue=self.queue, nssm_path=self.nssm_path, log_level=self.log_level, log_file=self.get_logfile(), workdir=self.workdir, user=self.user, manager_ip=self.manager_ip, manager_port=self.manager_port, broker_url=self.broker_url, min_workers=self.min_workers, max_workers=self.max_workers, includes=','.join(self.includes), virtualenv_path=VIRTUALENV, name=self.name, storage_dir=utils.internal.get_storage_directory(self.user), custom_environment=env_string, startup_policy=self.startup_policy, failure_reset_timeout=self.failure_reset_timeout, failure_restart_delay=self.failure_restart_delay ) self._logger.debug('Rendered configuration script: {0}'.format( self.config_path)) # run the configuration script self._logger.info('Running configuration script') self._runner.run(self.config_path) self._logger.debug('Successfully executed configuration script') # Add the celery config self._logger.info('Deploying SSL cert (if defined).') self._create_ssl_cert() self._logger.info('Deploying celery configuration.') self._create_celery_conf() # register plugins for plugin in included_plugins: self.register(plugin)
def create_config(self): # creating the installation script self._logger.info('Rendering configuration script "{0}" from template' .format(self.config_path)) utils.render_template_to_file( template_path='pm/nssm/nssm.conf.template', file_path=self.config_path, queue=self.queue, nssm_path=self.nssm_path, log_level=self.log_level.upper(), log_dir=self.log_dir, log_max_bytes=self.log_max_bytes, log_max_history=self.log_max_history, workdir=self.workdir, user=self.user, service_user=self.service_user, service_password=self.service_password, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, max_workers=self.max_workers, virtualenv_path=VIRTUALENV, name=self.name, custom_environment=self._create_env_string(), executable_temp_path=self.executable_temp_path, startup_policy=self.startup_policy, failure_reset_timeout=self.failure_reset_timeout, failure_restart_delay=self.failure_restart_delay, storage_dir=utils.internal.get_storage_directory(self.user), cluster_settings_path=self.cluster_settings_path ) self._logger.info('Rendered configuration script: {0}'.format( self.config_path)) # run the configuration script self._logger.info('Running configuration script') try: self._runner.run(self.config_path) except Exception: # Log the exception here, then re-raise it. This is done in order # to ensure that the full exception message is shown. self._logger.exception("Failure encountered while running " "configuration script") raise self._logger.info('Successfully executed configuration script')
def test_rendered_template_to_file(self): temp = utils.render_template_to_file( template_path=os.path.join('pm', 'initd', 'initd.conf.template'), rest_host='127.0.0.1' ) with open(temp) as f: rendered = f.read() self.assertTrue('export REST_HOST="127.0.0.1"' in rendered)
def test_rendered_template_to_file(self): temp = utils.render_template_to_file( template_path=os.path.join('pm', 'initd', 'initd.conf.template'), manager_ip='127.0.0.1' ) with open(temp) as f: rendered = f.read() self.assertTrue('export MANAGEMENT_IP=127.0.0.1' in rendered)
def create_config(self): self._logger.debug( 'Rendering configuration script "{0}" from template'.format( self.config_path)) utils.render_template_to_file( template_path='pm/detach/detach.conf.template', file_path=self.config_path, user=self.user, name=self.name, broker_url=self.broker_url, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, extra_env_path=self.extra_env_path, storage_dir=utils.internal.get_storage_directory(self.user), workdir=self.workdir, cluster_settings_path=self.cluster_settings_path)
def create_config(self): env_string = self._create_env_string() # creating the installation script self._logger.debug('Rendering configuration script "{0}" from template' .format(self.config_path)) utils.render_template_to_file( template_path='pm/nssm/nssm.conf.template', file_path=self.config_path, queue=self.queue, nssm_path=self.nssm_path, log_level=self.log_level, log_file=self.get_logfile(), workdir=self.workdir, user=self.user, rest_host=self.rest_host, rest_port=self.rest_port, rest_protocol=self.rest_protocol, file_server_host=self.file_server_host, file_server_port=self.file_server_port, file_server_protocol=self.file_server_protocol, security_enabled=self.security_enabled, verify_rest_certificate=self.verify_rest_certificate, local_rest_cert_file=self.local_rest_cert_file, rest_cert_content=self.rest_cert_content, broker_url=self.broker_url, min_workers=self.min_workers, max_workers=self.max_workers, virtualenv_path=VIRTUALENV, name=self.name, storage_dir=utils.internal.get_storage_directory(self.user), custom_environment=env_string, startup_policy=self.startup_policy, failure_reset_timeout=self.failure_reset_timeout, failure_restart_delay=self.failure_restart_delay ) self._logger.debug('Rendered configuration script: {0}'.format( self.config_path)) # run the configuration script self._logger.info('Running configuration script') self._runner.run(self.config_path) self._logger.debug('Successfully executed configuration script')
def create_script(self): self._logger.debug('Rendering init.d script from template') rendered = utils.render_template_to_file( template_path='pm/initd/initd.template', daemon_name=self.name, config_path=self.config_path) self._runner.run('sudo mkdir -p {0}'.format( os.path.dirname(self.script_path))) self._runner.run('sudo cp {0} {1}'.format(rendered, self.script_path)) self._runner.run('sudo rm {0}'.format(rendered)) self._runner.run('sudo chmod +x {0}'.format(self.script_path))
def create_config(self): self._logger.debug('Rendering configuration script "{0}" from template' .format(self.config_path)) utils.render_template_to_file( template_path='pm/detach/detach.conf.template', file_path=self.config_path, user=self.user, name=self.name, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, log_level=self.log_level.upper(), log_dir=self.log_dir, log_max_bytes=self.log_max_bytes, log_max_history=self.log_max_history, extra_env_path=self.extra_env_path, storage_dir=utils.internal.get_storage_directory(self.user), workdir=self.workdir, executable_temp_path=self.executable_temp_path, )
def create_config(self): self._logger.debug('Rendering configuration script "{0}" from template'.format(self.config_path)) utils.render_template_to_file( template_path="pm/detach/detach.conf.template", file_path=self.config_path, user=self.user, name=self.name, broker_url=self.broker_url, rest_host=self.rest_host, rest_port=self.rest_port, rest_protocol=self.rest_protocol, file_server_host=self.file_server_host, file_server_port=self.file_server_port, file_server_protocol=self.file_server_protocol, security_enabled=self.security_enabled, verify_rest_certificate=self.verify_rest_certificate, local_rest_cert_file=self.local_rest_cert_file, extra_env_path=self.extra_env_path, storage_dir=utils.internal.get_storage_directory(self.user), workdir=self.workdir, )
def create_config(self): self._logger.debug('Rendering configuration script "{0}" from template' .format(self.config_path)) utils.render_template_to_file( template_path='pm/detach/detach.conf.template', file_path=self.config_path, user=self.user, name=self.name, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, log_level=self.log_level.upper(), log_dir=self.log_dir, log_max_bytes=self.log_max_bytes, log_max_history=self.log_max_history, extra_env_path=self.extra_env_path, storage_dir=utils.internal.get_storage_directory(self.user), workdir=self.workdir, executable_temp_path=self.executable_temp_path, cluster_settings_path=self.cluster_settings_path )
def _get_rendered_script(self): self._logger.debug('Rendering SystemD script from template') return utils.render_template_to_file( template_path='pm/systemd/systemd.template', virtualenv_path=VIRTUALENV, user=self.user, queue=self.queue, config_path=self.config_path, max_workers=self.max_workers, name=self.name, extra_env_path=self.extra_env_path, )
def create_script(self): self._logger.debug('Rendering init.d script from template') rendered = utils.render_template_to_file( template_path='pm/initd/initd.template', daemon_name=self.name, config_path=self.config_path ) self._runner.run('sudo mkdir -p {0}'.format( os.path.dirname(self.script_path))) self._runner.run('sudo cp {0} {1}'.format(rendered, self.script_path)) self._runner.run('sudo rm {0}'.format(rendered)) self._runner.run('sudo chmod +x {0}'.format(self.script_path))
def _get_rendered_script(self): self._logger.debug('Rendering init.d script from template') return utils.render_template_to_file( template_path='pm/initd/initd.template', service_name=self.service_name, config_path=self.config_path, user=self.user, queue=self.queue, max_workers=self.max_workers, pidfile=self.pid_file, name=self.name, virtualenv_path=self.virtualenv, log_dir=self.log_dir)
def _get_rendered_script(self): self._logger.debug('Rendering init.d script from template') return utils.render_template_to_file( template_path='pm/initd/initd.template', service_name=self.service_name, config_path=self.config_path, user=self.user, queue=self.queue, max_workers=self.max_workers, pidfile=self.pid_file, name=self.name, virtualenv_path=self.virtualenv, log_dir=self.log_dir )
def _get_rendered_config(self): self._logger.debug( 'Rendering configuration script "{0}" from template'.format( self.config_path)) return utils.render_template_to_file( template_path='pm/systemd/systemd.conf.template', workdir=self.workdir, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, log_level=self.log_level.upper(), log_dir=self.log_dir, name=self.name, executable_temp_path=self.executable_temp_path, )
def _get_rendered_config(self): self._logger.debug('Rendering configuration script "{0}" from template' .format(self.config_path)) return utils.render_template_to_file( template_path='pm/systemd/systemd.conf.template', workdir=self.workdir, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, log_level=self.log_level.upper(), log_dir=self.log_dir, log_max_bytes=self.log_max_bytes, log_max_history=self.log_max_history, name=self.name, executable_temp_path=self.executable_temp_path, cluster_settings_path=self.cluster_settings_path )
def create_script(self): self._logger.debug('Rendering detached script from template') rendered = utils.render_template_to_file( template_path='pm/detach/detach.template', config_path=self.config_path, queue=self.queue, name=self.name, max_workers=self.max_workers, virtualenv_path=VIRTUALENV, workdir=self.workdir, pid_file=self.pid_file ) # no sudo needed, yey! self._runner.run('cp {0} {1}'.format(rendered, self.script_path)) self._runner.run('rm {0}'.format(rendered)) self._runner.run('chmod +x {0}'.format(self.script_path))
def _create_script(self): self._logger.debug('Rendering detached script from template') rendered = utils.render_template_to_file( template_path='pm/detach/detach.template', config_path=self.config_path, queue=self.queue, name=self.name, log_level=self.log_level, log_file=self.get_logfile(), pid_file=self.pid_file, broker_url=self.broker_url, min_workers=self.min_workers, max_workers=self.max_workers, includes_path=self.includes_path, virtualenv_path=VIRTUALENV) # no sudo needed, yey! self._runner.run('cp {0} {1}'.format(rendered, self.script_path)) self._runner.run('rm {0}'.format(rendered)) self._runner.run('chmod +x {0}'.format(self.script_path))
def _get_rendered_config(self): self._logger.debug( 'Rendering configuration script "{0}" from template'.format( self.config_path)) return utils.render_template_to_file( template_path='pm/initd/initd.conf.template', queue=self.queue, workdir=self.workdir, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, log_level=self.log_level.upper(), log_dir=self.log_dir, cron_respawn=str(self.cron_respawn).lower(), enable_cron_script=self.create_enable_cron_script(), disable_cron_script=self.create_disable_cron_script(), executable_temp_path=self.executable_temp_path, extra_env_path=self.extra_env_path, storage_dir=utils.internal.get_storage_directory(self.user), name=self.name, )
def _create_script(self): self._logger.debug('Rendering detached script from template') rendered = utils.render_template_to_file( template_path='pm/detach/detach.template', config_path=self.config_path, queue=self.queue, name=self.name, log_level=self.log_level, log_file=self.log_file, pid_file=self.pid_file, broker_url=self.broker_url, min_workers=self.min_workers, max_workers=self.max_workers, includes_path=self.includes_path, virtualenv_path=VIRTUALENV ) # no sudo needed, yey! self._runner.run('cp {0} {1}'.format(rendered, self.script_path)) self._runner.run('rm {0}'.format(rendered)) self._runner.run('chmod +x {0}'.format(self.script_path))
def create_script(self): self._logger.debug("Rendering detached script from template") rendered = utils.render_template_to_file( template_path="pm/detach/detach.template", config_path=self.config_path, queue=self.queue, name=self.name, log_level=self.log_level, log_file=self.get_logfile(), pid_file=self.pid_file, broker_url=self.broker_url, min_workers=self.min_workers, max_workers=self.max_workers, virtualenv_path=VIRTUALENV, workdir=self.workdir, ) # no sudo needed, yey! self._runner.run("cp {0} {1}".format(rendered, self.script_path)) self._runner.run("rm {0}".format(rendered)) self._runner.run("chmod +x {0}".format(self.script_path))
def _get_rendered_config(self): self._logger.debug('Rendering configuration script "{0}" from template' .format(self.config_path)) return utils.render_template_to_file( template_path='pm/initd/initd.conf.template', queue=self.queue, workdir=self.workdir, rest_host=self.rest_host, rest_port=self.rest_port, local_rest_cert_file=self.local_rest_cert_file, log_level=self.log_level.upper(), log_dir=self.log_dir, log_max_bytes=self.log_max_bytes, log_max_history=self.log_max_history, cron_respawn=str(self.cron_respawn).lower(), enable_cron_script=self.create_enable_cron_script(), disable_cron_script=self.create_disable_cron_script(), executable_temp_path=self.executable_temp_path, extra_env_path=self.extra_env_path, storage_dir=utils.internal.get_storage_directory(self.user), name=self.name, cluster_settings_path=self.cluster_settings_path )
def create_config(self): self._logger.debug('Rendering configuration script "{0}" from template' .format(self.config_path)) rendered = utils.render_template_to_file( template_path='pm/initd/initd.conf.template', queue=self.queue, workdir=self.workdir, rest_host=self.rest_host, rest_port=self.rest_port, rest_protocol=self.rest_protocol, file_server_host=self.file_server_host, file_server_port=self.file_server_port, file_server_protocol=self.file_server_protocol, security_enabled=self.security_enabled, verify_rest_certificate=self.verify_rest_certificate, local_rest_cert_file=self.local_rest_cert_file, rest_cert_content=self.rest_cert_content, broker_url=self.broker_url, user=self.user, min_workers=self.min_workers, max_workers=self.max_workers, virtualenv_path=VIRTUALENV, extra_env_path=self.extra_env_path, name=self.name, storage_dir=utils.internal.get_storage_directory(self.user), log_level=self.log_level, log_file=self.get_logfile(), pid_file=self.pid_file, cron_respawn=str(self.cron_respawn).lower(), enable_cron_script=self.create_enable_cron_script(), disable_cron_script=self.create_disable_cron_script() ) self._runner.run('sudo mkdir -p {0}'.format( os.path.dirname(self.config_path))) self._runner.run('sudo cp {0} {1}'.format(rendered, self.config_path)) self._runner.run('sudo rm {0}'.format(rendered))