Exemplo n.º 1
0
def setup_supervisor():
    site_root = join(home_directory(SITE_USER), 'site')
    upload_template('researchcompendia.conf',
                    '/etc/supervisor/conf.d/researchcompendia_web.conf',
                    context={
                        'command':
                        join(site_root, 'bin', 'runserver.sh'),
                        'user':
                        SITE_USER,
                        'group':
                        SITE_GROUP,
                        'logfile':
                        join(site_root, 'logs', 'gunicorn_supervisor.log'),
                    },
                    use_jinja=True,
                    use_sudo=True,
                    template_dir=TEMPLATE_DIR)
    upload_template('celeryd.conf',
                    '/etc/supervisor/conf.d/celeryd.conf',
                    context={
                        'command': join(site_root, 'bin', 'celeryworker.sh'),
                        'user': SITE_USER,
                        'group': SITE_GROUP,
                        'logfile': join(site_root, 'logs',
                                        'celery_worker.log'),
                    },
                    use_jinja=True,
                    use_sudo=True,
                    template_dir=TEMPLATE_DIR)
    supervisor.update_config()
Exemplo n.º 2
0
def add_task(name, timespec, user, command):
    """
    Add a cron task.

    The *command* will be run as *user* periodically.

    You can use any valid `crontab(5)`_ *timespec*, including the
    ``@hourly``, ``@daily``, ``@weekly``, ``@monthly`` and ``@yearly``
    shortcuts.

    Examples::

        from fabtools.cron import add_task

        # Run every month
        add_task('cleanup', '@monthly', 'alice', '/home/alice/bin/cleanup.sh')

        # Run every tuesday and friday at 5:30am
        add_task('reindex', '30 5 * * 2,4', 'bob', '/home/bob/bin/reindex.sh')

    .. _crontab(5): http://manpages.debian.net/cgi-bin/man.cgi?query=crontab&sektion=5

    """
    with NamedTemporaryFile() as script:
        script.write('%(timespec)s %(user)s %(command)s\n' % locals())
        script.flush()
        upload_template('/etc/cron.d/%(name)s' % locals(),
                        script.name,
                        context={},
                        chown=True,
                        use_sudo=True)
Exemplo n.º 3
0
def setup_gunicorn_script():
    bindir = join(SITE_DIR, 'bin')
    python_path = SITE_SETTINGS['repo_dir']

    upload_template('gunicorn.sh',
                    join(bindir, 'gunicorn.sh'),
                    context={
                        'settings_module':
                        SITE_SETTINGS['settings_module'],
                        'path_to_virtualenv':
                        join(SITE_DIR, SITE_SETTINGS['virtualenv']),
                        'user':
                        SITE_SETTINGS['user'],
                        'group':
                        SITE_SETTINGS['group'],
                        'site_dir':
                        SITE_DIR,
                        'wsgi_module':
                        SITE_SETTINGS['wsgi_module'],
                        'gunicorn_port':
                        SITE_SETTINGS['gunicorn_port'],
                        'python_path':
                        python_path,
                    },
                    use_jinja=True,
                    use_sudo=True,
                    template_dir=TEMPLATE_DIR)
Exemplo n.º 4
0
def _upload_template(filename,
                     destination,
                     context=None,
                     chown=True,
                     user='******',
                     **kwargs):
    kwargs['use_jinja'] = True
    kwargs['template_dir'] = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), os.path.pardir,
        'templates')
    kwargs['context'] = context
    kwargs['mkdir'] = False
    kwargs['chown'] = chown
    kwargs['user'] = user
    kwargs['use_sudo'] = True
    kwargs['backup'] = env.backup_conf_files
    if env.show_diff_when_upload and exists(destination):
        destination_temp = destination + '.temp'
        upload_template(filename, destination_temp, **kwargs)
        with warn_only():
            run('{} {} {}'.format(env.show_diff_when_upload, destination,
                                  destination_temp))
        run('rm {}'.format(destination))
        run('mv {} {}'.format(destination_temp, destination))
    else:
        upload_template(filename, destination, **kwargs)
Exemplo n.º 5
0
def sudo_upload_template(template,
                         dest,
                         context=None,
                         mode=None,
                         user_own=None,
                         **kwargs):
    """
    A wrapper around upload_template in fabtools. Used to upload template files.

    :param user_own: Set to user name that's supposed to own the file.
        If it is None, the uploading user's rights are used.
    :type user_own: str

    :return: None
    """
    if kwargs:
        context = (context or {}).copy()
        context.update(kwargs)
    files.upload_template(
        template,
        dest,
        context,
        use_jinja=True,
        template_dir=str(TEMPLATE_DIR),
        use_sudo=True,
        backup=False,
        mode=mode,
        chown=True,
        user=user_own)
Exemplo n.º 6
0
def add_task(name, timespec, user, command):
    """
    Add a cron task.

    The *command* will be run as *user* periodically.

    You can use any valid `crontab(5)`_ *timespec*, including the
    ``@hourly``, ``@daily``, ``@weekly``, ``@monthly`` and ``@yearly``
    shortcuts.

    Examples::

        from fabtools.cron import add_task

        # Run every month
        add_task('cleanup', '@monthly', 'alice', '/home/alice/bin/cleanup.sh')

        # Run every tuesday and friday at 5:30am
        add_task('reindex', '30 5 * * 2,4', 'bob', '/home/bob/bin/reindex.sh')

    .. _crontab(5): http://manpages.debian.net/cgi-bin/man.cgi?query=crontab&sektion=5

    """
    with NamedTemporaryFile() as script:
        script.write('%(timespec)s %(user)s %(command)s\n' % locals())
        script.flush()
        upload_template('/etc/cron.d/%(name)s' % locals(),
                        script.name,
                        context={},
                        chown=True,
                        use_sudo=True)
Exemplo n.º 7
0
def deploy_nginx_api_site(now):
    files.upload_template('templates/uwsgi.ini',  env.uwsgi_config_path(now),
        context={
           'config_path': env.apitaxi_config_path(now),
           'api_path': env.apitaxi_dir(now),
           'venv_path': env.apitaxi_venv_path(now),
           'uwsgi_file': env.uwsgi_file(now),
           'uwsgi_pid_file': env.uwsgi_pid_file(now),
           'uwsgi_log_dir': env.uwsgi_logdir,
           'uwsgi_launcher_logdir': env.uwsgi_launcher_logdir,
           'socket': env.uwsgi_socket(now),
           'processes': env.wsgi_processes,
           'threads': env.wsgi_threads
       }
    )

    uwsgi = path.join(env.apitaxi_venv_path(now), 'bin', 'uwsgi')
    require.supervisor.process('uwsgi_{}'.format(now),
        command='{} --ini {}'.format(uwsgi, env.uwsgi_config_path(now)),
        directory=env.apitaxi_venv_path(now),
        stdout_logfile = '/var/log/nginx/apitaxi.log',
        user='******'
    )

    test_uwsgi_is_started(now)

    require.nginx.site('apitaxi',
        template_source='templates/nginx_site.conf',
        domain_name=getattr(env.conf_api, 'HOST', 'localhost'),
        port=getattr(env.conf_api, 'PORT', 80),
        socket=env.uwsgi_socket(now)
    )
Exemplo n.º 8
0
def deploy_www_root():
    site_root = join(home_directory(SITE_USER), 'site')
    site_home = home_directory(SITE_USER)
    bindir = join(site_root, 'bin')

    with cd(home_directory(SITE_USER)):
        su('mkdir -p venvs site')

    with cd(site_root):
        su('mkdir -p logs bin env static')
        upload_template('runserver.sh',
                        join(bindir, 'runserver.sh'),
                        context={
                            'site_version': 'veyepar',
                            'site_home': site_home,
                            'site_name': SITE_USER,
                            'django_dir': join(SITE_NAME, 'dj'),
                            'wsgi_module': 'dj.wsgi',
                            'django_settings_module': 'dj.settings',
                        },
                        use_jinja=True,
                        use_sudo=True,
                        chown=True,
                        user=SITE_USER)

    with cd(bindir):
        su('chmod +x runserver.sh')
Exemplo n.º 9
0
def install():
    utils.deb.install('rxvt-unicode-256color')
    print('Uploading .Xresources...')
    upload_template('~/.Xresources', 'rxvt/Xresources')

    print('Uploading urxvtc...')
    upload_template('bin/urxvtc', 'rxvt/urxvtc', mkdir=True)
    run('chmod +x ~/bin/urxvtc')
Exemplo n.º 10
0
    def test_use_jinja_false(self, mock_upload_template):

        from fabtools.files import upload_template

        upload_template('filename', 'destination', use_jinja=False)

        args, kwargs = mock_upload_template.call_args
        self.assertEqual(kwargs['use_jinja'], False)
Exemplo n.º 11
0
    def test_mkdir(self, mock_upload_template, mock_run):

        from fabtools.files import upload_template

        upload_template('filename', '/path/to/destination', mkdir=True)

        args, kwargs = mock_run.call_args
        self.assertEqual(args[0], 'mkdir -p /path/to')
Exemplo n.º 12
0
def install_local_settings():
    settings_dir = join(home_directory(SITE_USER), 'site', SITE_NAME, 'dj', 'dj')
    with cd(settings_dir):
        upload_template('local_settings.py', 'local_settings.py',
            context={
                'secret_key': randomstring(32),
            },
            use_jinja=True, use_sudo=True, chown=True, user=SITE_USER)
Exemplo n.º 13
0
    def test_chown_user(self, mock_upload_template, mock_run_as_root):

        from fabtools.files import upload_template

        upload_template('filename', 'destination', chown=True, user='******')

        args, kwargs = mock_run_as_root.call_args
        self.assertEqual(args[0], 'chown alice: destination')
Exemplo n.º 14
0
    def test_chown_user(self, mock_upload_template, mock_run_as_root):

        from fabtools.files import upload_template

        upload_template('filename', 'destination', chown=True, user='******')

        args, kwargs = mock_run_as_root.call_args
        self.assertEqual(args[0], 'chown alice: destination')
Exemplo n.º 15
0
    def test_use_jinja_false(self, mock_upload_template):

        from fabtools.files import upload_template

        upload_template('filename', 'destination', use_jinja=False)

        args, kwargs = mock_upload_template.call_args
        self.assertEqual(kwargs['use_jinja'], False)
Exemplo n.º 16
0
    def test_mkdir(self, mock_upload_template, mock_run):

        from fabtools.files import upload_template

        upload_template('filename', '/path/to/destination', mkdir=True)

        args, kwargs = mock_run.call_args
        self.assertEqual(args[0], 'mkdir -p /path/to')
Exemplo n.º 17
0
def setup_server():
    """
    Setup project on clean Ubuntu server
    """

    sudo('apt-get update')

    require.deb.packages([
        'sudo',
        'mc',
        'git',
        'nginx',
        'supervisor',
        'uwsgi',
        'uwsgi-plugin-python',
        'libpq-dev',
    ])

    # Creating project paths
    sudo('mkdir {env.project_path:s} -p'.format(env=env))
    sudo('chown {env.project_user:s} {env.project_path:s}'.format(env=env))
    sudo('mkdir {env.venv_path:s} -p'.format(env=env))
    sudo('chown {env.project_user:s} {env.venv_path:s}'.format(env=env))

    git.clone(env.repository_url, path=env.project_path, use_sudo=False, user=env.project_user)
    git.checkout(path=env.project_path, branch=env.branch, use_sudo=False, user=env.project_user)

    require.python.virtualenv(env.venv_path, use_sudo=False)

    with virtualenv(env.venv_path):
        require.python.requirements(os.path.join(env.project_path, 'requirements.txt'))

    require.postgres.server()
    require.postgres.user(env.db_user, password=env.db_pass, createdb=False, createrole=True)
    require.postgres.database(env.db_name, env.db_user)

    upload_template(
        filename='conf/server_local.py',
        destination='%(settings_path)s/local.py' % env,
        context={
            'db_name': env.db_name,
            'db_pass': env.db_pass,
            'db_user': env.db_user,
        },
        use_jinja=True
    )

    with cd(env.manage_path):
        run('chmod ogu+x manage.py')

    uwsgi_setup()
    supervisor_setup()
    sudo('rm /etc/nginx/sites-enabled/default')
    nginx_setup()

    manage('syncdb')
    manage('migrate')
    manage('collectstatic --noinput')
Exemplo n.º 18
0
    def test_chown(self, mock_upload_template, mock_run_as_root):

        from fabric.api import env
        from fabtools.files import upload_template

        upload_template('filename', 'destination', chown=True)

        args, kwargs = mock_run_as_root.call_args
        self.assertEqual(args[0], 'chown %s: destination' % env.user)
Exemplo n.º 19
0
    def test_chown(self, mock_upload_template, mock_run_as_root):

        from fabric.api import env
        from fabtools.files import upload_template

        upload_template('filename', 'destination', chown=True)

        args, kwargs = mock_run_as_root.call_args
        self.assertEqual(args[0], 'chown %s: destination' % env.user)
Exemplo n.º 20
0
    def test_mkdir_sudo_user(self, mock_upload_template, mock_sudo):

        from fabtools.files import upload_template

        upload_template('filename', '/path/to/destination', mkdir=True, use_sudo=True, user='******')

        args, kwargs = mock_sudo.call_args
        self.assertEqual(args[0], 'mkdir -p /path/to')
        self.assertEqual(kwargs['user'], 'alice')
def setup_collectd():
    """ installs collectd and configures it to talk to graphite
    """
    require.deb.packages(['collectd',])
    hostname = run('hostname')
    upload_template('collectd.conf', '/etc/collectd/collectd.conf', use_jinja=True,
        context={'carbonhost': env.carbon, 'hostname': hostname},
        template_dir=TEMPLATE_DIR, use_sudo=True)
    sudo('/etc/init.d/collectd restart')
Exemplo n.º 22
0
def install_local_settings():
    settings_dir = join(home_directory(SITE_USER), 'site', SITE_NAME, 'dj', 'dj')
    staticdir = join(home_directory(SITE_USER), 'site', 'static')
    with cd(settings_dir):
        upload_template('local_settings.py', 'local_settings.py',
            context={
                'staticdir': staticdir,
                'secret_key': randomstring(32),
            },
            use_jinja=True, use_sudo=True, chown=True, user=SITE_USER)
Exemplo n.º 23
0
def upload_template(p, dest, ctx, mode='644'):
    files.upload_template(p.name,
                          dest,
                          ctx,
                          use_jinja=True,
                          template_dir=str(p.parent),
                          use_sudo=True,
                          mode=mode,
                          backup=False,
                          chown=True)
Exemplo n.º 24
0
def _upload_template(filename, destination, context=None, chown=True, user="******", **kwargs):
    kwargs["use_jinja"] = True
    kwargs["template_dir"] = os.path.join(os.path.dirname(os.path.realpath(__file__)), os.path.pardir, "templates")
    kwargs["context"] = context
    kwargs["mkdir"] = False
    kwargs["chown"] = chown
    kwargs["user"] = user
    kwargs["use_sudo"] = True
    kwargs["backup"] = env.backup_conf_files
    upload_template(filename, destination, **kwargs)
Exemplo n.º 25
0
def uwsgi_setup():
    upload_template(
        filename='conf/uwsgi.ini',
        destination='%(deploy_path)s/uwsgi_%(project_name)s.ini' % env,
        context={
            'project_name': env.project_name,
            'project_path': env.project_path,
            'venv_path': env.venv_path,
        },
        use_jinja=True
    )
Exemplo n.º 26
0
def add_task(name, timespec, user, command):
    """
    Add a cron task
    """
    with NamedTemporaryFile() as script:
        script.write('%(timespec)s %(user)s %(command)s\n' % locals())
        script.flush()
        upload_template('/etc/cron.d/%(name)s' % locals(),
            script.name,
            context={},
            use_sudo=True)
Exemplo n.º 27
0
def _upload_template(filename, destination, context=None, chown=True, user='******', **kwargs):
    kwargs['use_jinja'] = True
    kwargs['template_dir'] = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                          os.path.pardir, 'templates')
    kwargs['context'] = context
    kwargs['mkdir'] = False
    kwargs['chown'] = chown
    kwargs['user'] = user
    kwargs['use_sudo'] = True
    kwargs['backup'] = env.backup_conf_files
    upload_template(filename, destination, **kwargs)
Exemplo n.º 28
0
def add_task(name, timespec, user, command):
    """
    Add a cron task
    """
    with NamedTemporaryFile() as script:
        script.write('%(timespec)s %(user)s %(command)s\n' % locals())
        script.flush()
        upload_template('/etc/cron.d/%(name)s' % locals(),
                        script.name,
                        context={},
                        chown=True,
                        use_sudo=True)
Exemplo n.º 29
0
    def test_mkdir_sudo(self, mock_upload_template, mock_sudo):

        from fabtools.files import upload_template

        upload_template('filename',
                        '/path/to/destination',
                        mkdir=True,
                        use_sudo=True)

        args, kwargs = mock_sudo.call_args
        self.assertEqual(args[0], 'mkdir -p /path/to')
        self.assertEqual(kwargs['user'], None)
Exemplo n.º 30
0
def add_process(name, options=None):
    """
    Add a supervisor process
    """
    if options is None:
        options = {}
    options['name'] = name

    upload_template('/etc/supervisor/conf.d/%(name)s.conf' % locals(),
        'supervisor/%(name)s.conf' % locals(),
        context=options,
        use_sudo=True)
def crontab_update_index():
    site_root = join(home_directory(SITE_USER), 'site')
    bindir = join(site_root, 'bin')
    job = join(home_directory(SITE_USER), 'update_index')
    upload_template('update_index', job,
        context={
            'command': join(bindir, 'update_index.sh'),
            'logfile': join(site_root, 'logs', 'cron_update_index.log'),
        },
        use_jinja=True, use_sudo=True, template_dir=TEMPLATE_DIR)
    sudo('chown %s:%s %s' % (SITE_USER, SITE_USER, job))
    su('crontab %s' % job)
Exemplo n.º 32
0
def add_task(name, timespec, user, command, environment=None):
    """
    Add a cron task.

    The *command* will be run as *user* periodically.

    You can use any valid `crontab(5)`_ *timespec*, including the
    ``@hourly``, ``@daily``, ``@weekly``, ``@monthly`` and ``@yearly``
    shortcuts.

    You can also provide an optional dictionary of environment variables
    that should be set when running the periodic command.

    Examples::

        from fabtools.cron import add_task

        # Run every month
        add_task('cleanup', '@monthly', 'alice', '/home/alice/bin/cleanup.sh')

        # Run every tuesday and friday at 5:30am
        add_task('reindex', '30 5 * * 2,4', 'bob', '/home/bob/bin/reindex.sh')

    .. _crontab(5): http://manpages.debian.net/cgi-bin/man.cgi?query=crontab&sektion=5

    """
    if environment is None:
        environment = {}

    with NamedTemporaryFile() as script:

        # Write optional environment variables first
        for key, value in environment.iteritems():
            script.write('%(key)s=%(value)s\n' % locals())

        # Write the main crontab line
        script.write('%(timespec)s %(user)s %(command)s\n' % locals())

        script.flush()

        # Upload file
        filename = '/etc/cron.d/%(name)s' % locals()
        upload_template(
            filename=script.name,
            destination=filename,
            context={},
            chown=True,
            use_sudo=True,
        )

        # Fix permissions
        run_as_root('chmod 0644 %s' % filename)
Exemplo n.º 33
0
def setup_supervisor():
    site_root = join(home_directory(SITE_USER), 'site')
    upload_template('veyepar.conf', 
        '/etc/supervisor/conf.d/veyepar.conf',
        context={
            'command': join(site_root, 'bin', 'runserver.sh'),
            'user': SITE_USER,
            'group': SITE_GROUP,
            'logfile': join(site_root, 'logs', 'gunicorn_supervisor.log'),

        },
        use_jinja=True, use_sudo=True)
    supervisor.update_config()
Exemplo n.º 34
0
def setup_nginx():
    site_root = join(home_directory(SITE_USER), 'site')
    upload_template('veyepar_nginx',
        '/etc/nginx/sites-available/veyepar',
        context={
            'access_log': join(site_root, 'logs', 'access.log'),
            'error_log': join(site_root, 'logs', 'error.log'),
            'static_location': join(site_root, 'static/'),
            'media_location': join(site_root, 'media/'),
        },
        use_jinja=True, use_sudo=True)
    require.nginx.enabled('veyepar')
    require.nginx.disabled('default')
Exemplo n.º 35
0
def deploy_supervisor():
    upload_template('supervised_process.conf.j2',
                    '/etc/supervisor/conf.d/%s.conf' % SITE_NAME,
                    context={
                        'supervised_process': SITE_NAME,
                        'site_dir': SITE_DIR,
                        'site_user': SITE_USER,
                        'group': SITE_USER,
                    },
                    template_dir=TEMPLATE_DIR,
                    use_jinja=True,
                    use_sudo=True)
    supervisor.update_config()
Exemplo n.º 36
0
def deploy_supervisor():
    upload_template('supervised_process.conf.j2',
                    '/etc/supervisor/conf.d/%s.conf' % SITE_NAME,
                    context={
                        'supervised_process': SITE_NAME,
                        'site_dir': SITE_DIR,
                        'site_user': SITE_USER,
                        'group': SITE_USER,
                    },
                    template_dir=TEMPLATE_DIR,
                    use_jinja=True,
                    use_sudo=True)
    supervisor.update_config()
Exemplo n.º 37
0
def add_task(name, timespec, user, command, environment=None):
    """
    Add a cron task.

    The *command* will be run as *user* periodically.

    You can use any valid `crontab(5)`_ *timespec*, including the
    ``@hourly``, ``@daily``, ``@weekly``, ``@monthly`` and ``@yearly``
    shortcuts.

    You can also provide an optional dictionary of environment variables
    that should be set when running the periodic command.

    Examples::

        from fabtools.cron import add_task

        # Run every month
        add_task('cleanup', '@monthly', 'alice', '/home/alice/bin/cleanup.sh')

        # Run every tuesday and friday at 5:30am
        add_task('reindex', '30 5 * * 2,4', 'bob', '/home/bob/bin/reindex.sh')

    .. _crontab(5): http://manpages.debian.net/cgi-bin/man.cgi?query=crontab&sektion=5

    """
    if environment is None:
        environment = {}

    with NamedTemporaryFile() as script:

        # Write optional environment variables first
        for key, value in environment.iteritems():
            script.write('%(key)s=%(value)s\n' % locals())

        # Write the main crontab line
        script.write('%(timespec)s %(user)s %(command)s\n' % locals())

        script.flush()

        # Upload file
        filename = '/etc/cron.d/%(name)s' % locals()
        upload_template(filename,
                        script.name,
                        context={},
                        chown=True,
                        use_sudo=True)

        # Fix permissions
        run_as_root('chmod 0644 %s' % filename)
Exemplo n.º 38
0
def setup_nginx_site():
    nginx_site = SITE_NAME
    static_dir = SITE_SETTINGS['repo_dir']
    upload_template('nginx_site.conf',
                    '/etc/nginx/sites-available/%s' % nginx_site,
                    context={
                        'server_name': SITE_SETTINGS['server_name'],
                        'gunicorn_port': SITE_SETTINGS['gunicorn_port'],
                        'path_to_static': join(static_dir, 'static'),
                        'site_dir': SITE_DIR,
                        'static_parent': '%s/' % static_dir,
                    },
                    use_jinja=True,
                    use_sudo=True,
                    template_dir=TEMPLATE_DIR)
    require.nginx.enabled(nginx_site)
def setup_nginx():
    site_root = join(home_directory(SITE_USER), 'site')
    upload_template('researchcompendia_nginx',
        '/etc/nginx/sites-available/researchcompendia',
        context={
            'server_name': env.site,
            'access_log': join(site_root, 'logs', 'access.log'),
            'error_log': join(site_root, 'logs', 'error.log'),
            'static_location': join(site_root, 'static/'),
            'media_location': join(site_root, 'media/'),
        },
        use_jinja=True, use_sudo=True, template_dir=TEMPLATE_DIR)
    require.nginx.enabled('researchcompendia')
    require.nginx.disabled('default')
    put(template_path('maintenance_nginx'), '/etc/nginx/sites-available/maintenance', use_sudo=True)
    put(template_path('maintenance_index.html'), '/usr/share/nginx/www/index.html', use_sudo=True)
Exemplo n.º 40
0
def supervisor_setup():
    upload_template(
        filename='conf/supervisor.conf',
        destination='%(deploy_path)s/supervisor_%(project_name)s.conf' % env,
        context={
            'project_name': env.project_name,
            'deploy_path': env.deploy_path,
            'log_path': env.log_path,
        },
        use_jinja=True
    )

    sudo('ln -s -f %(deploy_path)s/supervisor_%(project_name)s.conf '
         '/etc/supervisor/conf.d/%(project_name)s.conf' % env)
    supervisor.update_config()
    supervisor.restart_process('all')
Exemplo n.º 41
0
def nginx_setup():
    upload_template(
        filename='conf/nginx.conf',
        destination='%(deploy_path)s/nginx_%(project_name)s.conf' % env,
        context={
            'project_name': env.project_name,
            'static_path': env.static_path,
            'media_path':env.media_path,
            'log_path': env.log_path
        },
        use_jinja=True
    )

    sudo('ln -s -f %(deploy_path)s/nginx_%(project_name)s.conf '
         '/etc/nginx/sites-enabled/%(project_name)s.conf' % env)
    restart('nginx')
Exemplo n.º 42
0
def setup_collectd():
    """ installs collectd and configures it to talk to graphite
    """
    require.deb.packages([
        'collectd',
    ])
    hostname = run('hostname')
    upload_template('collectd.conf',
                    '/etc/collectd/collectd.conf',
                    use_jinja=True,
                    context={
                        'carbonhost': env.carbon,
                        'hostname': hostname
                    },
                    template_dir=TEMPLATE_DIR,
                    use_sudo=True)
    sudo('/etc/init.d/collectd restart')
Exemplo n.º 43
0
def setup_supervisor():
    site_root = join(home_directory(SITE_USER), 'site')
    upload_template('veyepar.conf',
                    '/etc/supervisor/conf.d/veyepar.conf',
                    context={
                        'command':
                        join(site_root, 'bin', 'runserver.sh'),
                        'user':
                        SITE_USER,
                        'group':
                        SITE_GROUP,
                        'logfile':
                        join(site_root, 'logs', 'gunicorn_supervisor.log'),
                    },
                    use_jinja=True,
                    use_sudo=True)
    supervisor.update_config()
Exemplo n.º 44
0
def deploy_nginx():
    frequire('SERVER_NAME', provided_by=('vagrant',))
    upload_template('site.conf.j2', 
                    '/etc/nginx/sites-available/%s' % SITE_NAME,
                    context={
                        'nginx_server_name': env['SERVER_NAME'],
                        'site_dir': SITE_DIR,
                        'static_dir': join(SITE_DIR, 'site_media', 'static'),
                        'static_parent_dir': join(SITE_DIR, 'site_media'),
                        'gunicorn_port': '8001',
                    },
                    template_dir=TEMPLATE_DIR,
                    use_jinja=True,
                    use_sudo=True,
                    )
    nginx.enabled(SITE_NAME)
    nginx.disabled('default')
Exemplo n.º 45
0
def crontab_update_index():
    site_root = join(home_directory(SITE_USER), 'site')
    bindir = join(site_root, 'bin')
    job = join(home_directory(SITE_USER), 'update_index')
    upload_template('update_index',
                    job,
                    context={
                        'command':
                        join(bindir, 'update_index.sh'),
                        'logfile':
                        join(site_root, 'logs', 'cron_update_index.log'),
                    },
                    use_jinja=True,
                    use_sudo=True,
                    template_dir=TEMPLATE_DIR)
    sudo('chown %s:%s %s' % (SITE_USER, SITE_USER, job))
    su('crontab %s' % job)
Exemplo n.º 46
0
def setup_supervisor():
    supervised_process = SITE_SETTINGS['supervised_process']
    bindir = join(SITE_DIR, 'bin')
    logdir = join(SITE_DIR, 'logs')
    upload_template('supervised_site.conf',
                    '/etc/supervisor/conf.d/%s.conf' % supervised_process,
                    context={
                        'supervised_process': supervised_process,
                        'command': join(bindir, 'gunicorn.sh'),
                        'user': SITE_SETTINGS['user'],
                        'group': SITE_SETTINGS['group'],
                        'logfile': join(logdir, 'gunicorn.log'),
                        'site_dir': bindir,
                    },
                    use_jinja=True,
                    use_sudo=True,
                    template_dir=TEMPLATE_DIR)
    supervisor.update_config()
Exemplo n.º 47
0
def deploy_nginx():
    """ ensure that nginx is installed and our site is enabled """
    require('managed', 'server_name')
    nginx.server()
    upload_template(
        'seattle2015-site.conf.j2',
        '/etc/nginx/sites-available/seattle2015.conf',
        context={
            'server_name': env.server_name,
            'managed': env.managed,
        },
        use_jinja=True,
        use_sudo=True,
        template_dir=env.deploy_dir,
    )
    nginx.enabled('seattle2015.conf')
    nginx.disabled('default')
    restart_nginx()
Exemplo n.º 48
0
def setup_nginx_site():
    nginx_site = SITE_NAME
    static_dir = SITE_SETTINGS["repo_dir"]
    upload_template(
        "nginx_site.conf",
        "/etc/nginx/sites-available/%s" % nginx_site,
        context={
            "server_name": SITE_SETTINGS["server_name"],
            "gunicorn_port": SITE_SETTINGS["gunicorn_port"],
            "path_to_static": join(static_dir, "static"),
            "site_dir": SITE_DIR,
            "static_parent": "%s/" % static_dir,
        },
        use_jinja=True,
        use_sudo=True,
        template_dir=TEMPLATE_DIR,
    )
    require.nginx.enabled(nginx_site)
Exemplo n.º 49
0
def _adjust_app_settings(venv):
    local_settings_path = os.path.join(LOCAL_BASE_DIR, 'deploy',
                                       'prod_settings.py')
    if not os.path.exists(local_settings_path):
        raise Exception('Cannot Find Production Settings File: %s' %
                        local_settings_path)

    remote_settings_path = os.path.join(REPO_PATH, 'togile', 'settings',
                                        'prod_settings.py')

    require.files.file(remote_settings_path, source=local_settings_path,
                       owner=USER, use_sudo=True)
    static_dir = os.path.join(venv, 'www')
    context = {
        'static': static_dir
    }
    files.upload_template(local_settings_path, remote_settings_path,
                          context=context, user=USER, use_sudo=True)
Exemplo n.º 50
0
def deploy_nginx():
    frequire('SERVER_NAME', provided_by=('vagrant', ))
    upload_template(
        'site.conf.j2',
        '/etc/nginx/sites-available/%s' % SITE_NAME,
        context={
            'nginx_server_name': env['SERVER_NAME'],
            'site_dir': SITE_DIR,
            'static_dir': join(SITE_DIR, 'site_media', 'static'),
            'static_parent_dir': join(SITE_DIR, 'site_media'),
            'gunicorn_port': '8001',
        },
        template_dir=TEMPLATE_DIR,
        use_jinja=True,
        use_sudo=True,
    )
    nginx.enabled(SITE_NAME)
    nginx.disabled('default')
Exemplo n.º 51
0
def _prepare_service(venv):
    # logs
    log_dir = os.path.join(venv, 'log')
    require.directory(log_dir, owner=USER, use_sudo=True)

    # Nginx
    require.nginx.disabled('default')

    conf = 'nginx/togile.conf'
    nginx_log = os.path.join(log_dir, 'nginx.log')
    app = os.path.join(REPO_PATH, 'frontend', 'app')
    static = os.path.join(venv, 'www')
    require.nginx.site(tg.NGINX['server_name'], template_source=conf,
                       nginx_log=nginx_log, static=static, togile_app=app)

    # Ensure running ...
    require.nginx.server()

    # CIRCUS

    # Upstart Conf
    circus_dir = os.path.join(venv, 'circus')
    require.directory(circus_dir, owner=USER, use_sudo=True)

    context = {
        'venv': venv,
        'circus': circus_dir,
        'togile': REPO_PATH,
        'user': tg.TOGILE_USER[0]
    }
    files.upload_template('circus/circus.conf', '/etc/init/circus.conf',
                          context=context, use_sudo=True)
    # Web INI
    web_ini = os.path.join(context['circus'], 'web.ini')
    files.upload_template('circus/circus.ini', web_ini, context=context,
                          user=USER, use_sudo=True)

    # Start Circus
    with settings(warn_only=True):
        # Stop circus if running ... ignore error anyway
        sudo('service circus stop')
        sleep(2)

    sudo('service circus start')
Exemplo n.º 52
0
def configure_nginx(distro):
    """
    Add Nginx configuration
    """
    # Local webvirtmgr site template
    conf = os.path.join(LOCAL_BASE_DIR, "deploy", "fabric", "templates",
                        "nginx.conf")
    # Remote location
    conf_path = os.path.join("/etc/nginx/conf.d", "webvirtmgr.conf")
    context = {
        "server_name": fsettings.SERVER_NAME
    }

    # Upload template to server
    files.upload_template(conf, conf_path, context=context, use_sudo=True)

    # Nginx, make sure `default` website is not running.
    if distro in ["Debian", "Ubuntu"]:
        disable_site("default")
    elif distro in ["Fedora"]:
        # Fedora places the default server:80 in nginx.conf!
        # we will replace nginx.conf
        default = "/etc/nginx/nginx.conf"
        default_bak = default + ".bak"

        # Local default nginx.conf template
        conf = os.path.join(LOCAL_BASE_DIR, "deploy", "fabric",
                            "templates", "original.nginx.conf")

        if not files.is_file(default_bak):
            # only replace backup if required
            sudo("mv %s %s" % (default, default + ".bak"))

        # Upload new nginx.conf to server
        files.upload_template(conf, default, use_sudo=True)
    else:
        default = "/etc/nginx/conf.d/default.conf"
        if files.is_file(default):
            sudo("mv %s %s" % (default, default + ".bak"))

    # Ensure running ...
    # require.nginx.server()
    require.service.restart("nginx")
Exemplo n.º 53
0
def setup_supervisor():

    # hacky workaround to ???
    sudo('touch /var/run/supervisor.sock')
    sudo('chmod 777 /var/run/supervisor.sock')
    sudo('service supervisor restart')

    site_root = join(home_directory(SITE_USER), 'site')
    upload_template('veyepar.conf', 
        '/etc/supervisor/conf.d/veyepar.conf',
        context={
            'command': join(site_root, 'bin', 'runserver.sh'),
            'user': SITE_USER,
            'group': SITE_GROUP,
            'logfile': join(site_root, 'logs', 'gunicorn_supervisor.log'),

        },
        use_jinja=True, use_sudo=True)
    supervisor.update_config()
Exemplo n.º 54
0
def put_runserver(venv):
    frequire('DJANGO_SETTINGS_MODULE', provided_by=('vagrant', ))
    destination_file = join(SITE_DIR, 'bin', 'runserver.sh')
    upload_template('runserver.sh.j2',
                    destination_file,
                    context={
                        'settings_module': env['DJANGO_SETTINGS_MODULE'],
                        'venv_dir': venv,
                        'site_user': SITE_USER,
                        'site_group': SITE_USER,
                        'log_level': 'info',
                        'site_dir': join(CLONE_DIR, 'bugtracker'),
                        'wsgi_module': 'bugtracker.wsgi',
                        'repo_dir': CLONE_DIR,
                        'gunicorn_port': '8001',
                    },
                    template_dir=TEMPLATE_DIR,
                    use_jinja=True,
                    use_sudo=True,
                    chown=True,
                    user=SITE_USER)
    sudo('chmod +x %s' % destination_file)
Exemplo n.º 55
0
def setup_nginx():
    site_root = join(home_directory(SITE_USER), 'site')
    upload_template('researchcompendia_nginx',
                    '/etc/nginx/sites-available/researchcompendia',
                    context={
                        'server_name': env.site,
                        'access_log': join(site_root, 'logs', 'access.log'),
                        'error_log': join(site_root, 'logs', 'error.log'),
                        'static_location': join(site_root, 'static/'),
                        'media_location': join(site_root, 'media/'),
                    },
                    use_jinja=True,
                    use_sudo=True,
                    template_dir=TEMPLATE_DIR)
    require.nginx.enabled('researchcompendia')
    require.nginx.disabled('default')
    put(template_path('maintenance_nginx'),
        '/etc/nginx/sites-available/maintenance',
        use_sudo=True)
    put(template_path('maintenance_index.html'),
        '/usr/share/nginx/www/index.html',
        use_sudo=True)