Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 53 lines (45 sloc) 1.984 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
from __future__ import with_statement
from fabric.api import *
from fabric.contrib.files import exists, append
from StringIO import StringIO

@task
def deploy(service_name, port=2090):
    '''Deploy (or upgrade) PyBossa service named `service_name` on optional
`port` (default 2090)'''
    basedir = '/home/okfn/var/srvc'
    app_dir = basedir + '/' + service_name
    src_dir = app_dir + '/' + 'src'
    code_dir = src_dir + '/' + 'pybossa'
    pip_path = app_dir + '/bin/pip'
    if not exists(src_dir):
        run('virtualenv %s' % app_dir)
        run('mkdir -p %s' % src_dir)
    run('%s install gunicorn' % pip_path)
    run('%s install -e git+https://github.com/PyBossa/pybossa#egg=pybossa' % pip_path)
    with cd(code_dir):
        run('git submodule init')
        run('git submodule update')

    supervisor_path = '/etc/supervisor/conf.d/%s.conf' % service_name
    if not exists(supervisor_path):
        log_path = app_dir + '/log'
        run('mkdir -p %s' % log_path)
        templated = supervisor_config % {
                'service_name': service_name,
                'app_dir': app_dir,
                'log_path': log_path,
                'port': port
                }
        put(StringIO(templated), supervisor_path, use_sudo=True)
        sudo('/etc/init.d/supervisor status')
        sudo('/etc/init.d/supervisor force-reload')
    print('Restarting supervised process for %s' % service_name)
    sudo('supervisorctl restart %s' % service_name)
    print('You will now need to have your web server proxy to port: %s' % port)


supervisor_config = '''[program:%(service_name)s]
command=%(app_dir)s/bin/gunicorn "pybossa.web:app" --bind=127.0.0.1:%(port)s --workers=2 --max-requests=500 --name=%(service_name)s --error-logfile=%(log_path)s/%(service_name)s.gunicorn.error.log

; user that owns virtual environment.
user=okfn
stdout_logfile=%(log_path)s/%(service_name)s.log
stderr_logfile=%(log_path)s/%(service_name)s.error.log
autostart=true
'''

Something went wrong with that request. Please try again.