Example #1
0
def deploy(branch=None):
    """Deploy to a given environment."""
    require('environment')
    if branch is not None:
        env.branch = branch
    requirements = False
    migrations = False
    # Fetch latest changes
    with cd(env.code_root):
        with settings(user=env.project_user):
            run('git fetch origin')
        # Look for new requirements or migrations
        requirements = match_changes(env.branch, "'requirements\/'")
        migrations = match_changes(env.branch, "'\/migrations\/'")
        if requirements or migrations:
            supervisor_command('stop %(environment)s:*' % env)
        with settings(user=env.project_user):
            run("git reset --hard origin/%(branch)s" % env)
    upload_local_settings()
    if requirements:
        update_requirements()
        # New requirements might need new tables/migrations
        syncdb()
    elif migrations:
        syncdb()
    collectstatic()
    supervisor_command('restart %(environment)s:*' % env)
Example #2
0
def deploy(branch=None, full=False):
    """Deploy to a given environment."""
    require('environment')
    if branch is not None:
        env.branch = branch
    requirements = False if not full else True
    migrations = False if not full else True
    # Fetch latest changes
    with cd(env.code_root):
        with settings(user=env.project_user):
            run('git fetch origin')
        # Look for new requirements or migrations
        changes = run("git diff origin/%(branch)s --stat-name-width=9999" % env)
        requirements = match_changes(changes, r"requirements/")
        migrations = match_changes(changes, r"/migrations/")
        if requirements or migrations:
            supervisor_command('stop %(environment)s:*' % env)
        with settings(user=env.project_user):
            run("git reset --hard origin/%(branch)s" % env)
    if requirements:
        update_requirements()
        # New requirements might need new tables/migrations
        syncdb()
    elif migrations:
        syncdb()
    collectstatic()
    supervisor_command('restart %(environment)s:*' % env)
Example #3
0
def upload_supervisor_conf():
    """Upload Supervisor configuration from the template."""

    require("environment", provided_by=env.environments)
    template = os.path.join(env.templates_dir, "supervisor.conf")
    destination = os.path.join(env.services, "supervisor", "%(environment)s.conf" % env)
    _upload_template(template, destination, context=env, user=env.deploy_user)
    supervisor.supervisor_command("update")
Example #4
0
def setup_server(*roles):
    """Install packages and add configurations for server given roles."""
    require('environment')
    # Set server locale
    sudo('/usr/sbin/update-locale LANG=en_US.UTF-8')
    roles = list(roles)
    if roles == ['all', ]:
        roles = SERVER_ROLES
    if 'base' not in roles:
        roles.insert(0, 'base')
    install_packages(*roles)
    if 'db' in roles:
        if console.confirm(u"Do you want to reset the Postgres cluster?.", default=False):
            # Ensure the cluster is using UTF-8
            pg_version = postgres.detect_version()
            sudo('pg_dropcluster --stop %s main' % pg_version, user='******')
            sudo('pg_createcluster --start -e UTF-8 --locale en_US.UTF-8 %s main' % pg_version,
                 user='******')
        postgres.create_db_user(username=env.project_user)
        postgres.create_db(name=env.db, owner=env.project_user)
    if 'app' in roles:
        # Create project directories and install Python requirements
        project_run('mkdir -p %(root)s' % env)
        project_run('mkdir -p %(log_dir)s' % env)
        # FIXME: update to SSH as normal user and use sudo
        # we ssh as the project_user here to maintain ssh agent
        # forwarding, because it doesn't work with sudo. read:
        # http://serverfault.com/questions/107187/sudo-su-username-while-keeping-ssh-key-forwarding
        with settings(user=env.project_user):
            # TODO: Add known hosts prior to clone.
            # i.e. ssh -o StrictHostKeyChecking=no [email protected]
            run('git clone %(repo)s %(code_root)s' % env)
            with cd(env.code_root):
                run('git checkout %(branch)s' % env)
        # Install and create virtualenv
        with settings(hide('everything'), warn_only=True):
            test_for_pip = run('which pip')
        if not test_for_pip:
            sudo("easy_install -U pip")
        with settings(hide('everything'), warn_only=True):
            test_for_virtualenv = run('which virtualenv')
        if not test_for_virtualenv:
            sudo("pip install -U virtualenv")
        project_run('virtualenv -p python2.7 --clear --distribute %s' % env.virtualenv_root)
        path_file = os.path.join(env.virtualenv_root, 'lib', 'python2.7', 'site-packages', 'project.pth')
        files.append(path_file, env.code_root, use_sudo=True)
        sudo('chown %s:%s %s' % (env.project_user, env.project_user, path_file))
        sudo('npm install [email protected] -g')
        update_requirements()
        upload_supervisor_app_conf(app_name=u'gunicorn')
        upload_supervisor_app_conf(app_name=u'group')
        # Restart services to pickup changes
        supervisor_command('reload')
        supervisor_command('restart %(environment)s:*' % env)
    if 'lb' in roles:
        nginx.remove_default_site()
        nginx.upload_nginx_site_conf(site_name=u'%(project)s-%(environment)s.conf' % env)
Example #5
0
def update_service_confs():
    """Update supervisor configuration."""
    require('environment')
    if not env.vagrant:
        upload_newrelic_conf()
    upload_supervisor_app_conf(app_name=u'gunicorn')
    upload_supervisor_app_conf(app_name=u'group')
    nginx.upload_nginx_site_conf(site_name=u'%(project)s-%(environment)s.conf' % env)
    # Restart services to pickup changes
    supervisor_command('reload')
def update_service_confs():
    """Update supervisor configuration."""
    require("environment")
    if not env.vagrant:
        upload_newrelic_conf()
    upload_supervisor_app_conf(app_name=u"gunicorn")
    upload_supervisor_app_conf(app_name=u"group")
    nginx.upload_nginx_site_conf(site_name=u"%(project)s-%(environment)s.conf" % env)
    # Restart services to pickup changes
    supervisor_command("reload")
Example #7
0
def setup_server(*roles):
    """Install packages and add configurations for server given roles."""
    require("environment")
    # Set server locale
    sudo("/usr/sbin/update-locale LANG=en_US.UTF-8")
    install_packages(*roles)
    if "db" in roles:
        if console.confirm(u"Do you want to reset the Postgres cluster?.", default=False):
            # Ensure the cluster is using UTF-8
            sudo("pg_dropcluster --stop 9.1 main", user="******")
            sudo("pg_createcluster --start -e UTF-8 9.1 main", user="******")
        postgres.create_db_user(username=env.project_user)
        postgres.create_db(name=env.db, owner=env.project_user)
    if "app" in roles:
        # Create project directories and install Python requirements
        project_run("mkdir -p %(root)s" % env)
        project_run("mkdir -p %(log_dir)s" % env)
        with settings(user=env.project_user):
            # TODO: Add known hosts prior to clone.
            # i.e. ssh -o StrictHostKeyChecking=no [email protected]
            sshagent_run("git clone %(repo)s %(code_root)s" % env)
        project_run("git checkout %(branch)s" % env)
        # Install and create virtualenv
        with settings(hide("everything"), warn_only=True):
            test_for_pip = run("which pip")
        if not test_for_pip:
            sudo("easy_install -U pip")
        with settings(hide("everything"), warn_only=True):
            test_for_virtualenv = run("which virtualenv")
        if not test_for_virtualenv:
            sudo("pip install -U virtualenv")
        project_run("virtualenv -p python2.6 --clear --distribute %s" % env.virtualenv_root)
        path_file = os.path.join(env.virtualenv_root, "lib", "python2.6", "site-packages", "project.pth")
        files.append(path_file, env.code_root, use_sudo=True)
        sudo("chown %s:%s %s" % (env.project_user, env.project_user, path_file))
        sudo("npm install less -g")
        update_requirements()
        upload_supervisor_app_conf(app_name=u"gunicorn")
        upload_supervisor_app_conf(app_name=u"group")
        # Restart services to pickup changes
        supervisor_command("reload")
        supervisor_command("restart %(environment)s:*" % env)
    if "lb" in roles:
        nginx.remove_default_site()
        nginx.upload_nginx_site_conf(site_name=u"%(project)s-%(environment)s.conf" % env)
Example #8
0
def setup_server(*roles):
    """Install packages and add configurations for server given roles."""
    require('environment')

    roles = list(roles)

    if not roles:
        abort("setup_server requires one or more server roles, e.g. setup_server:app or setup_server:all")

    if roles == ['all', ]:
        roles = SERVER_ROLES
    if 'base' not in roles:
        roles.insert(0, 'base')
    if 'app' in roles:
        # Create project directories and install Python requirements
        project_run('mkdir -p %(root)s' % env)
        project_run('mkdir -p %(log_dir)s' % env)
        # FIXME: update to SSH as normal user and use sudo
        # we ssh as the project_user here to maintain ssh agent
        # forwarding, because it doesn't work with sudo. read:
        # http://serverfault.com/questions/107187/sudo-su-username-while-keeping-ssh-key-forwarding
        with settings(user=env.project_user):
            if not files.exists(env.code_root):
                run('git clone --quiet %(repo)s %(code_root)s' % env)
            with cd(env.code_root):
                run('git checkout %(branch)s' % env)
        if not files.exists(env.virtualenv_root):
            project_run('virtualenv --quiet -p python2.7 --clear --distribute %s' % env.virtualenv_root)
            # TODO: Why do we need this next part?
            path_file = os.path.join(env.virtualenv_root, 'lib', 'python2.7', 'site-packages', 'project.pth')
            files.append(path_file, env.code_root, use_sudo=True)
            sudo('chown %s:%s %s' % (env.project_user, env.project_user, path_file))
        update_requirements()
        upload_supervisor_app_conf(app_name=u'gunicorn')
        upload_supervisor_app_conf(app_name=u'group')
        # Restart services to pickup changes
        supervisor_command('reload')
        supervisor_command('restart %(environment)s:*' % env)
    if 'lb' in roles:
        nginx.remove_default_site()
        nginx.upload_nginx_site_conf(site_name=u'%(project)s-%(environment)s.conf' % env)
Example #9
0
def update_services():
    """Update nginx and supervisor configuration files."""
    require('environment')
    nginx.upload_nginx_site_conf(site_name=u'%(project)s-%(environment)s.conf' % env)
    supervisor_command('stop all')
    # upload_supervisor_app_conf(app_name=u'celery')
    # upload_supervisor_app_conf(app_name=u'gunicorn')
    upload_supervisor_app_conf(app_name=u'group')
    supervisor_command('reload')
    supervisor_command('restart %(environment)s:*' % env)
Example #10
0
def load_geo_files():
    require('environment')
    supervisor_command('stop %(environment)s:*' % env)
    manage_run('import_columbus_county -d /tmp/columbusco-shapefiles')
    supervisor_command('start %(environment)s:*' % env)
Example #11
0
 def test_restart_all(self):
     "Restart all supervisor managed processes."
     supervisor.supervisor_command("restart all")
     self.assertSudoCommand('supervisorctl restart all')
Example #12
0
 def test_update_command(self):
     "Call update command."
     supervisor.supervisor_command("update")
     self.assertSudoCommand('supervisorctl update')
Example #13
0
def restart_supervisor():
    """Restart all Supervisor controlled processes."""

    require("environment", provided_by=env.environments)
    supervisor.supervisor_command("restart %(environment)s:*" % env)
Example #14
0
def restart_server():
    """Restart gunicorn server."""

    require("environment", provided_by=env.environments)
    command = "restart %(environment)s:%(environment)s-server" % env
    supervisor.supervisor_command(command)