forked from devincachu/devincachu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
76 lines (48 loc) · 2.25 KB
/
fabfile.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# -*- coding: utf-8 -*-
import os
from fabric.api import cd, env, run, settings
env.root = os.path.dirname(__file__)
env.app = os.path.join(env.root, 'devincachu')
env.base_dir = '/usr/home/devincachu'
env.project_root = os.path.join(env.base_dir, 'devincachu')
env.app_root = os.path.join(env.project_root, 'devincachu')
env.virtualenv = os.path.join(env.project_root, 'env')
env.shell = '/bin/sh -c'
def update_app():
run('([ -d %(project_root)s ] && cd %(project_root)s && git pull origin master) || (cd %(base_dir)s && git clone git://github.com/devincachu/devincachu.git)' % env)
def create_virtualenv_if_need():
run('[ -d %(virtualenv)s ] || virtualenv --no-site-packages --unzip-setuptools %(virtualenv)s' % env)
def pip_install():
run('CFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib %(virtualenv)s/bin/pip install -r %(project_root)s/requirements_env.txt' % env)
def create_local_settings():
with cd(env.project_root):
run('%(virtualenv)s/bin/python gerar_settings_local.py %(app_root)s/settings_local.py.example' % env)
def collect_static_files():
with cd(env.app_root):
run('%(virtualenv)s/bin/python manage.py collectstatic -v 0 --noinput' % env)
def syncdb():
with cd(env.app_root):
run('%(virtualenv)s/bin/python manage.py syncdb --noinput' % env)
def start_gunicorn():
with cd(env.app_root):
run('%(virtualenv)s/bin/gunicorn_django --pid=gunicorn.pid --daemon --workers=3 --access-logfile=devincachu_access.log --error-logfile=devincachu_error.log --bind=unix:/tmp/devincachu.sock' % env)
def stop_gunicorn():
with settings(warn_only=True):
pid = run('cat %(app_root)s/gunicorn.pid' % env)
run('kill -TERM %s' % pid)
def graceful_gunicorn():
with settings(warn_only=True):
pid = run('cat %(app_root)s/gunicorn.pid' % env)
run('kill -HUP %s' % pid)
def reload_nginx():
run("su -m root -c '/usr/local/etc/rc.d/nginx reload'")
def clean():
run("su -m root -c 'rm -rf /usr/local/etc/nginx/cache/data/devincachu/*'")
def createsuperuser():
with cd(env.app_root):
run("%(virtualenv)s/bin/python manage.py createsuperuser" % env)
def deploy():
update_app()
create_virtualenv_if_need()
pip_install()
collect_static_files()