def ensure_production_settings(): notify('Configuring production settings.') context = SENSITIVE cuisine.mode_sudo() content = cuisine.text_template(templates.production_settings, context) cuisine.file_write(PROJECT['ROOT'] + '/moment/conf/production.py', content) restart()
def hosts_conf(): notify('Writing hostname and hosts files.') cuisine.mode_sudo() sudo('echo "{NAME}" > /etc/hostname'.format(NAME=MACHINE['KEY'])) sudo('hostname -F /etc/hostname') hosts = cuisine.text_template(templates.hosts, MACHINE) cuisine.file_append('/etc/hosts', hosts)
def gunicorn_process_ensure(path, template, config, key_env, venv_path='.venv'): with virtualenv(path, venv_path): python_package_ensure('gunicorn') run("cp %s %s" % (template, config)) file_update(config, lambda x: text_template(x,key_env)) dir_ensure('%s/logs' % path) dir_ensure('%s/run' % path)
def ensure_production_settings(): notify("Configuring production settings.") context = SENSITIVE cuisine.mode_sudo() content = cuisine.text_template(templates.production_settings, context) cuisine.file_write(PROJECT["ROOT"] + "/moment/conf/production.py", content) restart()
def gunicorn_ensure(path, template, config, venv_path='.venv'): with virtualenv(path, venv_path): python_package_ensure('gunicorn') run("cp %s %s" % (template, config)) file_update(config, lambda x: text_template(x,env)) dir_ensure('%s/logs' % path) dir_ensure('%s/run' % path)
def gunicorn_supervisor_ensure(project_path, project_name, template, key_env): with mode_sudo(), cd(project_path): config = '/etc/supervisor/conf.d/%s.conf' % project_name package_ensure('supervisor') python_package_ensure('setproctitle') run("cp %s %s" % (template, config)) file_update(config, lambda x: text_template(x,key_env)) run("supervisorctl reread") run("supervisorctl update") run("supervisorctl restart %s" % (project_name))
def nginx_ensure(name, template): with mode_sudo(): package_ensure('nginx') run("cp %s /etc/nginx/sites-available/%s" % (template, name)) file_update('/etc/nginx/sites-available/%s' % name, lambda x: text_template(x,env)) if not file_exists("/etc/nginx/sites-enabled/%s" % name): run("ln -s -t /etc/nginx/sites-enabled /etc/nginx/sites-available/%s " % ( env.project_name)) file_unlink('/etc/nginx/sites-enabled/default') run("service nginx restart")
def gunicorn_supervisor_ensure(project_name, template): with mode_sudo(): config = '/etc/supervisor/conf.d/%s.conf' % project_name package_ensure('supervisor') python_package_ensure('setproctitle') run("cp %s %s" % (template, config)) file_update(config, lambda x: text_template(x,env)) run("supervisorctl reread") run("supervisorctl update") run("supervisorctl restart %s" % (project_name))
def config(): """Ensures the app configuration is in place.""" utilities.notify(u'Ensuring the app configuration settings.') context = env cuisine.mode_sudo() content = cuisine.text_template(env.app_config_template, context) cuisine.file_write(env.app_config_file, content) execute(restart)
def management(): """Ensures the app process management is in place.""" utilities.notify(u'Ensuring the app management settings.') context = env cuisine.mode_sudo() content = cuisine.text_template(env.app_management_template, context) cuisine.file_write(env.app_management_file, content) execute(update) execute(restart)
def nginx_ensure(project_path, name, template, key_env): with mode_sudo(), cd(project_path): package_ensure('nginx') run("cp %s /etc/nginx/sites-available/%s" % (template, name)) file_update('/etc/nginx/sites-available/%s' % name, lambda x: text_template(x,key_env)) if not file_exists("/etc/nginx/sites-enabled/%s" % name): run("ln -s -t /etc/nginx/sites-enabled /etc/nginx/sites-available/%s " % ( name)) file_unlink('/etc/nginx/sites-enabled/default') run("service nginx restart")
def ensure_rq(): notify('Configuring RQ.') context = { 'ACTION_DATE': MACHINE['ACTION_DATE'], 'NAME': PROJECT['NAME'], 'KEY': KEY, 'PROJECT_ROOT': PROJECT['ROOT'], 'PROJECT_ENV': PROJECT['ENV'], } cuisine.mode_sudo() content = cuisine.text_template(templates.rq_supervisor, context) cuisine.file_write('/etc/supervisor/conf.d/' + KEY + '-rq.conf', content) restart()
def ensure_rq(): notify("Configuring RQ.") context = { "ACTION_DATE": MACHINE["ACTION_DATE"], "NAME": PROJECT["NAME"], "KEY": KEY, "PROJECT_ROOT": PROJECT["ROOT"], "PROJECT_ENV": PROJECT["ENV"], } cuisine.mode_sudo() content = cuisine.text_template(templates.rq_supervisor, context) cuisine.file_write("/etc/supervisor/conf.d/" + KEY + "-rq.conf", content) restart()
def install_nginx_upstart(version): """Install nginx upstart config.""" install_dir = os.path.join(_INSTALL_DIR, 'nginx', version) nginx_bin = os.path.join(install_dir, 'sbin', 'nginx') nginx_pid = os.path.join(install_dir, 'logs', 'nginx.pid') context = { 'nginx_bin': nginx_bin, 'nginx_pid': nginx_pid, } nginx_tpl = os.path.join(ETC_DIR, 'init', 'nginx.conf') tpl_content = file_local_read(nginx_tpl) content = text_template(tpl_content, context) with mode_sudo(): file_write('/etc/init/nginx.conf', content)
def ensure_nginx(): notify("Configuring nginx.") context = { "ACTION_DATE": MACHINE["ACTION_DATE"], "NAME": PROJECT["NAME"], "KEY": KEY, "APP_LOCATION": PROJECT["APP_LOCATION"], "APP_PORT": PROJECT["APP_PORT"], "LOCATION": MACHINE["LOCATION"], "PORT": MACHINE["PORT"], "PROJECT_ROOT": PROJECT["ROOT"], "ACCESS_LOG": PROJECT["LOGS"]["NGINX_ACCESS"], "ERROR_LOG": PROJECT["LOGS"]["NGINX_ERROR"], "SERVER_NAMES": " ".join(PROJECT["DOMAINS"]), } cuisine.mode_sudo() content = cuisine.text_template(templates.nginx, context) cuisine.file_write("/etc/nginx/sites-enabled/" + KEY, content) sudo("/etc/init.d/nginx restart")
def ensure_nginx(): notify('Configuring nginx.') context = { 'ACTION_DATE': MACHINE['ACTION_DATE'], 'NAME': PROJECT['NAME'], 'KEY': KEY, 'APP_LOCATION': PROJECT['APP_LOCATION'], 'APP_PORT': PROJECT['APP_PORT'], 'LOCATION': MACHINE['LOCATION'], 'PORT': MACHINE['PORT'], 'PROJECT_ROOT': PROJECT['ROOT'], 'ACCESS_LOG': PROJECT['LOGS']['NGINX_ACCESS'], 'ERROR_LOG': PROJECT['LOGS']['NGINX_ERROR'], 'SERVER_NAMES': ' '.join(PROJECT['DOMAINS']) } cuisine.mode_sudo() content = cuisine.text_template(templates.nginx, context) cuisine.file_write('/etc/nginx/sites-enabled/' + KEY, content) sudo('/etc/init.d/nginx restart')
def install_upstart(): """Install nginx upstart config.""" version = get_config()['version'] install_dir = os.path.join(_INSTALL_DIR, 'nginx', version) nginx_bin = os.path.join(install_dir, 'sbin', 'nginx') nginx_pid = os.path.join(install_dir, 'logs', 'nginx.pid') context = { 'nginx_bin': nginx_bin, 'nginx_pid': nginx_pid, } nginx_tpl = os.path.join(ETC_DIR, 'init', 'nginx.conf') tpl_content = cuisine.file_local_read(nginx_tpl) content = cuisine.text_template(tpl_content, context) with cuisine.mode_sudo(): cuisine.file_write('/etc/init/nginx.conf', content)
def install_nginx_site_conf(version, nginx_file, context=None): """Install nginx config per site.""" if not os.path.exists(nginx_file): abort("Nginx conf {0} not found".format(nginx_file)) site_name = os.path.basename(nginx_file) install_dir = os.path.join(_INSTALL_DIR, 'nginx', version) conf_file = os.path.join(install_dir, 'conf', 'sites-enabled', site_name) if context: tpl_content = open(nginx_file, 'rb').read() content = text_template(tpl_content, context) with mode_sudo(): file_write(conf_file, content) else: with mode_sudo(): file_upload(conf_file, nginx_file)
def install_nginx_conf(version, nginx_file): """Install global nginx config.""" install_dir = os.path.join(_INSTALL_DIR, 'nginx', version) conf_file = os.path.join(install_dir, 'conf', 'nginx.conf') if not os.path.exists(nginx_file): abort("Nginx conf {0} not found".format(nginx_file)) nginx_pid = os.path.join(install_dir, 'logs', 'nginx.pid') context = { 'nginx_user': NGINX_USER, 'nginx_pid': nginx_pid, } tpl_content = open(nginx_file, 'rb').read() content = text_template(tpl_content, context) with mode_sudo(): file_write(conf_file, content)
def put_site_conf(nginx_file, context=None): """Install nginx config per site.""" version = get_config()['version'] if not os.path.exists(nginx_file): fab.abort("Nginx conf {0} not found".format(nginx_file)) site_name = os.path.basename(nginx_file) install_dir = os.path.join(_INSTALL_DIR, 'nginx', version) conf_file = os.path.join(install_dir, 'conf', 'sites-enabled', site_name) if context: tpl_content = open(nginx_file, 'rb').read() content = cuisine.text_template(tpl_content, context) with cuisine.mode_sudo(): cuisine.file_write(conf_file, content) else: with cuisine.mode_sudo(): cuisine.file_upload(conf_file, nginx_file)
def put_conf(nginx_file): """Install global nginx config.""" version = get_config()['version'] install_dir = os.path.join(_INSTALL_DIR, 'nginx', version) conf_file = os.path.join(install_dir, 'conf', 'nginx.conf') if not os.path.exists(nginx_file): fab.abort("Nginx conf {0} not found".format(nginx_file)) nginx_pid = os.path.join(install_dir, 'logs', 'nginx.pid') context = { 'nginx_user': NGINX_USER, 'nginx_pid': nginx_pid, } tpl_content = open(nginx_file, 'rb').read() content = cuisine.text_template(tpl_content, context) with cuisine.mode_sudo(): cuisine.file_write(conf_file, content)
def ensure_gunicorn(): notify("Configuring gunicorn.") context = { "ACTION_DATE": MACHINE["ACTION_DATE"], "NAME": PROJECT["NAME"], "KEY": KEY, "APP_LOCATION": PROJECT["APP_LOCATION"], "APP_PORT": PROJECT["APP_PORT"], "APP_TIMEOUT": PROJECT["APP_TIMEOUT"], "APP_WSGI": PROJECT["APP_WSGI"], "APP_WORKERS": PROJECT["APP_WORKERS"], "LOCATION": MACHINE["LOCATION"], "PORT": MACHINE["PORT"], "PROJECT_ROOT": PROJECT["ROOT"], "PROJECT_ENV": PROJECT["ENV"], "ACCESS_LOG": PROJECT["LOGS"]["GUNICORN_ACCESS"], "ERROR_LOG": PROJECT["LOGS"]["GUNICORN_ERROR"], } cuisine.mode_sudo() content = cuisine.text_template(templates.gunicorn_supervisor, context) cuisine.file_write("/etc/supervisor/conf.d/" + KEY + "-gunicorn.conf", content) restart()
def ensure_gunicorn(): notify('Configuring gunicorn.') context = { 'ACTION_DATE': MACHINE['ACTION_DATE'], 'NAME': PROJECT['NAME'], 'KEY': KEY, 'APP_LOCATION': PROJECT['APP_LOCATION'], 'APP_PORT': PROJECT['APP_PORT'], 'APP_TIMEOUT': PROJECT['APP_TIMEOUT'], 'APP_WSGI': PROJECT['APP_WSGI'], 'APP_WORKERS': PROJECT['APP_WORKERS'], 'LOCATION': MACHINE['LOCATION'], 'PORT': MACHINE['PORT'], 'PROJECT_ROOT': PROJECT['ROOT'], 'PROJECT_ENV': PROJECT['ENV'], 'ACCESS_LOG': PROJECT['LOGS']['GUNICORN_ACCESS'], 'ERROR_LOG': PROJECT['LOGS']['GUNICORN_ERROR'], } cuisine.mode_sudo() content = cuisine.text_template(templates.gunicorn_supervisor, context) cuisine.file_write('/etc/supervisor/conf.d/' + KEY + '-gunicorn.conf', content) restart()
def profile_conf(): notify('Configuring .profile settings.') profile = cuisine.text_template(templates.profile, MACHINE) cuisine.file_append(MACHINE['OWNER_PROFILE'], profile) run('source ' + MACHINE['OWNER_PROFILE'])
def django_config_ensure(path, template, config): with cd(path): run("cp %s %s" % (template, config)) file_update(config, lambda x: text_template(x,env))
def ensure_settings(): utilities.notify(u'Configuring local settings.') context = env content = cuisine.text_template(env.project_config_template, context) cuisine.file_write(env.project_config_file, content)
def django_config_ensure(project_path, template, config, key_env): with cd(project_path): run("cp %s %s" % (template, config)) file_update(config, lambda x: text_template(x, key_env))