def execute_local(storage, paths, logger, recipe_name, command): command = render_string(command, { 'storage': storage.get, 'paths': paths.get, }) command = 'cd {} && {}'.format(paths.get('local.code'), command) # show log message logger.info('execute local command "{}"'.format(command), recipe_name) process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True) for line in iter(process.stdout.readline, ''): logger.success(line.strip('\n'), recipe_name) for line in iter(process.stderr.readline, ''): logger.error(line.strip('\n'), recipe_name) process.stdout.close() process.stderr.close() exit_code = process.wait() if exit_code != 0: raise RecipeException( 'Execution error with command "{}"'.format(command))
def wrap_commands_with_path(storage, paths, commands): path_commands = [] for command in commands: command = 'cd {} && {}'.format(paths.get('remote.code'), command) command = render_string(command, { 'storage': storage.get, 'paths': paths.get, }) path_commands.append(command) return path_commands
def render(demons, storage, paths): items = [] path_item = '{}/supervisor/item.j2'.format( paths.get('catapult.templates'), ) for demon in demons: command = render_string( demon['command'], { 'release_path': paths.get('remote.code'), 'storage': storage.get, 'paths': paths.get }) numprocs = 1 if demon['type'] == BOT_MIRRORING: numprocs = demon['instances'] item = render_path( path_item, { 'program': demon['name'], 'process_name': '%(program_name)s_%(process_num)02d', 'command': command, 'user': storage.get('config.deploy.user'), 'numprocs': str(numprocs), 'storage': storage.get, 'paths': paths.get }) items.append(item) path_supervisor = '{}/supervisor/supervisor.j2'.format( paths.get('catapult.templates'), ) generated = render_path( path_supervisor, { 'items': '\n\n'.join(map(str, items)), 'storage': storage.get, 'paths': paths.get }) return generated
def execute_remote(storage, paths, ssh, logger, recipe_name, command, types, is_sudo): if is_sudo: command = 'sudo {}'.format(command) command = 'cd {} && {}'.format(paths.get('remote.code'), command) command = render_string(command, { 'storage': storage.get, 'paths': paths.get, }) # show log message logger.info('execute remote command "{}"'.format(command), recipe_name) for host_type in types: hosts = storage.get_hosts(host_type) for host in hosts: ssh.execute_on_host(host, command)
def generate_apps(applications, storage, paths): apps = [] for application in applications: command = render_string( application['command'], { 'release_path': paths.get('remote.code'), 'storage': storage.get, 'paths': paths.get, }) generated = { 'name': application['name'], 'script': command, 'instances': application['instances'], 'exec_mode': application['mode'], 'cwd': paths.get('remote.code') } apps.append(generated) return apps
def render(crons, storage, paths): items = [] path_item = '{}/crontab/item.j2'.format(paths.get('catapult.templates'), ) for cron in crons: command = render_string( cron['command'], { 'release_path': paths.get('remote.code'), 'storage': storage.get, 'paths': paths.get, }) item = render_path( path_item, { 'minutes': str(cron['planning']['minutes']), 'hours': str(cron['planning']['hours']), 'dom': str(cron['planning']['dom']), 'mon': str(cron['planning']['mon']), 'dow': str(cron['planning']['dow']), 'command': command, 'user': storage.get('config.deploy.user'), 'storage': storage.get, 'paths': paths.get, }) items.append(item) path_crontab = '{}/crontab/crontab.j2'.format( paths.get('catapult.templates'), ) generated = render_path( path_crontab, { 'items': '\n\n'.join(map(str, items)), 'storage': storage.get, 'paths': paths.get, }) return generated
def render(template_path, config, storage, paths): path_parameter = '{}/nginx/parameter.j2'.format( paths.get('catapult.templates'), ) path_location = '{}/nginx/location.j2'.format( paths.get('catapult.templates'), ) locations = [] for location in config['locations']: parameters = [] for key, value in location['configs'].items(): if type(value) is list: for item in value: generated = render_path(path_parameter, { 'key': key, 'value': item }) parameters.append(generated) else: generated = render_path(path_parameter, { 'key': key, 'value': value }) parameters.append(generated) generated = render_path(path_location, { 'modifier': location['modifier'], 'match': location['match'], 'parameters': '\n'.join(parameters), 'storage': storage.get, 'paths': paths.get, }) locations.append(generated) index_files = config['index_files'] if type(index_files) is list: index_files = ' '.join(index_files) root = render_string(config['root'], { 'release_path': paths.get('remote.code'), 'storage': storage.get, 'paths': paths.get, }) item = render_path(template_path, { 'root': root, 'index_files': index_files, 'locations': '\n'.join(locations), 'storage': storage.get, 'paths': paths.get, }) path_nginx = '{}/nginx/nginx.j2'.format( paths.get('catapult.templates'), ) generated = render_path(path_nginx, { 'item': item, 'storage': storage.get, 'paths': paths.get, }) return generated