fabfile.py 2.24 KB
Newer Older
1 2 3 4 5 6
from __future__ import with_statement
from fabric.api import *
from fabric.colors import *
from fabric.utils import puts, abort

env.use_ssh_config = True
7
apps_to_migrate = ('workflows','streams',)
8 9 10 11 12 13 14 15 16 17 18 19

def live():
    """ doloci live server kot aktivni """
    env.os = 'ubuntu'
    env.hosts = ['git@workflow.ijs.si']
    env.branch = 'master'

def deploy():
    """ deploy na serverju
    uporaba:
    $ fab live deploy
    """
20 21 22 23 24 25 26
    with prefix('source /srv/django-envs/mothra/bin/activate'):
        with cd('/srv/django-projects/mothra'):
            puts(yellow("[Pulling from origin, on branch %s]" % (env.branch,)))
            run('git pull origin %s' % (env.branch,))
            run('git checkout %s' % (env.branch,))

            puts(yellow("[Installing packages]"))
27

28 29 30 31 32 33 34 35 36
            run('pip install -qr requirements.txt')

            puts(yellow("[Migrating apps]"))
            for app in apps_to_migrate:
                puts("--> [Migrating %s]" % (app,))
                run('python manage.py migrate %s --no-initial-data' % (app, ))

            puts(yellow("[Collecting static files]"))
            run("python manage.py collectstatic --noinput")
37

38
            puts(yellow("[Auto importing packages]"))
39
            run("python manage.py import_all")
40

41 42 43 44
        with cd('/srv/django-projects/supervisor'):
            puts(yellow("[Restarting the run streams daemon"))
            run('supervisorctl restart runstreams')

Janez K's avatar
Janez K committed
45 46 47
        #with cd('/srv/django-projects/supervisor'):
        #    puts(yellow("[Restarting the gunicorn daemon"))
        #    run('supervisorctl restart mothra')
Janez K's avatar
Janez K committed
48

49 50
            #puts(yellow("[Compressing]"))
            #run('python manage.py compress')
51

52 53 54 55
def supervisorstat():
    "supervisor statistika na serverju"
    with prefix('source /srv/django-envs/mothra/bin/activate'):
        with cd('/srv/django-projects/supervisor'):
Janez K's avatar
Janez K committed
56
            run('tail /srv/django-logs/runstreams.stdout.log')
57 58
            run('supervisorctl status')

Janez K's avatar
Janez K committed
59

60 61 62 63 64 65 66 67 68 69 70 71
def apache_restart():
    """restarta apache service
    primer:
    $ fab dev apache_restart
    $ fab live apache_restart
    """
    if env.os == 'ubuntu':
        sudo('service apache2 restart')
    elif env.os == 'arch':
        sudo('rc.d restart httpd')
    else:
        abort('env.os ni definiran, kaj je zdej to')