コード例 #1
0
def setup_settings():
    """
    Takes the dploy/<STAGE>_settings.py template and upload it to remote
    django project location (as local_settings.py)
    """
    print(cyan("Setuping django settings project on {}".format(env.stage)))
    project_dir = get_project_dir()
    project_name = ctx('django.project_name')
    stage_settings = '{stage}_settings.py'.format(stage=env.stage)
    templates = [
        os.path.join('./dploy/', stage_settings),
        os.path.join('./', project_name, 'local_settings.py-dist'),
        os.path.join('./', project_name, 'local_settings.py-default'),
        os.path.join('./', project_name, 'local_settings.py-example'),
        os.path.join('./', project_name, 'local_settings.py.dist'),
        os.path.join('./', project_name, 'local_settings.py.default'),
        os.path.join('./', project_name, 'local_settings.py.example'),
    ]

    template = select_template(templates)
    if not template:
        print(red('ERROR: the project does not have a settings template'))
        print("The project must provide at least one of these file:")
        print("\n - {}\n".format("\n - ".join(templates)))
        sys.exit(1)

    filename = os.path.basename(template)
    templates_dir = os.path.dirname(template)
    _settings_dest = os.path.join(project_dir, project_name,
                                  'local_settings.py')
    upload_template(filename, _settings_dest, template_dir=templates_dir)
コード例 #2
0
def setup():
    """
    Configure uWSGI
    """
    print(cyan('Configuring uwsgi {}'.format(env.stage)))
    project_dir = get_project_dir()
    wsgi_file = os.path.join(project_dir, ctx('django.project_name'),
                             'wsgi.py')
    uwsgi_ini = os.path.join(project_dir, 'uwsgi.ini')
    context = {'ctx': ctx, 'project_dir': project_dir, 'wsgi_file': wsgi_file}
    log_file = '{}/uwsgi.log'.format(ctx('logs.dirs.root'))
    sudo('touch {logfile}'.format(logfile=log_file))
    sudo('chown {user}:{group} {logfile}'.format(logfile=log_file,
                                                 user=ctx('system.user'),
                                                 group=ctx('system.group')))
    upload_template('uwsgi.template', uwsgi_ini, context=context)
コード例 #3
0
ファイル: cron.py プロジェクト: vhrebenuk/python-dploy
def setup():
    """
    Configure Cron if a dploy/cron.template exists
    """
    # Cron doesn't like dots in filename
    filename = ctx('nginx.server_name').replace('.', '_')
    dest = os.path.join(ctx('cron.config_path'), filename)
    try:
        upload_template('cron.template', dest)
        print(cyan('Configuring cron {}'.format(env.stage)))
        # We make sure the cron file always ends with a blank line, otherwise
        # it will be ignored by cron. Yeah, that's retarded.
        sudo("echo -en '\n' >> {}".format(dest))
        sudo('chown -R root:root {}'.format(dest))
        sudo('chmod 644 {}'.format(dest))
    except TemplateNotFound:
        print(yellow('Skipping cron configuration on {}'.format(env.stage)))
コード例 #4
0
ファイル: supervisor.py プロジェクト: vhrebenuk/python-dploy
def setup():
    """
    Configure supervisor to monitor the uwsgi process
    """
    print(cyan('Configuring supervisor {}'.format(env.stage)))
    if not fabtools.deb.is_installed('supervisor'):
        fabtools.deb.install('supervisor')
    project_dir = get_project_dir()
    uwsgi_ini = os.path.join(project_dir, 'uwsgi.ini')
    name = ctx('supervisor.program_name')
    context = {'uwsgi_ini': uwsgi_ini}
    dest = os.path.join(
        ctx('supervisor.dirs.root'),
        '{}.conf'.format(ctx('nginx.server_name').replace('.', '_')))
    upload_template('supervisor.template', dest, context=context)
    fabtools.supervisor.update_config()
    if fabtools.supervisor.process_status(name) == 'RUNNING':
        fabtools.supervisor.restart_process(name)
    elif fabtools.supervisor.process_status(name) == 'STOPPED':
        fabtools.supervisor.start_process(name)
コード例 #5
0
def setup():
    """
    Configure nginx, will trigger letsencrypt setup if required
    """
    print(cyan('Configuring nginx on {}'.format(env.stage)))
    context = {
        'ssl_letsencrypt': False,
        'ssl_with_dhparam': False,
        'ssl_cert': None,
        'ssl_key': None,
    }

    if ctx('ssl.letsencrypt'):
        execute('letsencrypt.setup')
    elif ctx('ssl.key') and ctx('ssl.cert'):
        ssl = True
        dhparams = ctx('ssl.dhparam', default=False)
        key = ctx('ssl.key', default=False)
        cert = ctx('ssl.cert', default=False)

        if key and files.exists(key, use_sudo=True):
            context['ssl_key'] = ctx('ssl.key')
        if cert and files.exists(cert, use_sudo=True):
            context['ssl_cert'] = ctx('ssl.cert')
        if dhparams and files.exists(dhparams, use_sudo=True):
            context['ssl_with_dhparam'] = True
        if ssl:
            upload_template(
                'nginx_ssl.template', ctx('nginx.config_path'), context=context)
    else:
        upload_template(
            'nginx.template', ctx('nginx.config_path'), context=context)

    if files.exists(ctx('nginx.document_root'), use_sudo=True):
        sudo('chown -R {user}:{group} {path}'.format(
            path=ctx('nginx.document_root'), user=ctx('system.user'),
            group=ctx('system.group')))

    sudo('service nginx reload')
コード例 #6
0
def setup():
    """
    Configure SSL with letsencrypt's certbot for the domain
    """
    server_name = ctx("nginx.server_name")
    path_letsencrypt = '/etc/letsencrypt/live'
    path_dhparams = '/etc/letsencrypt/ssl-dhparams.pem'
    path_key = '{}/{}/privkey.pem'.format(path_letsencrypt, server_name)
    path_cert = '{}/{}/fullchain.pem'.format(path_letsencrypt, server_name)

    if not fabtools.deb.is_installed('certbot'):
        execute(install)

    if not files.exists('/etc/letsencrypt/ssl-dhparams.pem', use_sudo=True):
        sudo('openssl dhparam -out /etc/letsencrypt/ssl-dhparams.pem 2048')

    if not files.exists('/etc/letsencrypt/options-ssl-nginx.conf',
                        use_sudo=True):
        upload_template('options-ssl-nginx.conf.template',
                        '/etc/letsencrypt/options-ssl-nginx.conf')

    if not files.exists(path_cert, use_sudo=True):
        upload_template('nginx_letsencrypt_init.template',
                        ctx('nginx.config_path'))
        sudo('certbot --authenticator webroot --installer nginx -d {}'.format(
            server_name))

    upload_template('nginx_letsencrypt.template',
                    ctx('nginx.config_path'),
                    context={
                        'ssl': {
                            'letsencrypt': True,
                            'dhparams': path_dhparams,
                            'key': path_key,
                            'cert': path_cert,
                        }
                    })