-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathfabfile.py
101 lines (86 loc) · 2.07 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
"""
Fabfile for Randomise Me
"""
from fabric.api import *
from fabric.colors import red, green
web = ['[email protected]']
#web = ['[email protected]']
PROJ_DIR = '/home/app/randomise_me'
VENV_BIN = '/home/app/randomise_me/bin/{0}'
#PROJ_DIR = '/usr/local/ohc/'
#VENV_BIN = '/usr/local/ohc/rm/bin/{0}'
venv_bin = lambda x: VENV_BIN.format(x)
VENV_PY = venv_bin('python')
VENV_CTL = venv_bin('supervisorctl')
@hosts(web)
def mkenv():
"""
Set up the directory environment required
Return: None
Exceptions: None
"""
run('mkdir -p /usr/local/ohc/var/run')
run('mkdir -p /usr/local/ohc/log/supervisord')
def manage(what):
"""
Run a manage.py command
Return: None
Exceptions: None
"""
with cd(PROJ_DIR):
run('{0} manage.py {1}'.format(VENV_PY, what))
def supervisorctl(what):
"""
Run a supervisorctl command
Arguments:
- `what`: the command to run
Return: None
Exceptions: None
"""
run('{ctl} {what}'.format(ctl=VENV_CTL, what=what))
def migrate():
"""
Update the database
"""
manage('syncdb --migrate')
def stop():
"""
Stop the application in production
"""
run("kill -9 `cat /usr/local/ohc/var/run/supervisord.pid`")
@hosts(web)
def start():
"""
Start the application in production.
"""
with cd(PROJ_DIR):
supervisord = venv_bin('supervisord')
run('{supervisord} -c etc/production.conf'.format(supervisord=supervisord))
@hosts(web)
def deploy():
"""
Make it so!
"""
with cd(PROJ_DIR):
run('git pull origin master --tags') #not ssh - key stuff
run('{0} install -r requirements.txt'.format(venv_bin('pip')))
manage('collectstatic --noinput')
migrate()
restart()
@hosts(web)
def restart():
"""
Restart the application
"""
with cd(PROJ_DIR):
supervisorctl('reread')
supervisorctl('restart all')
@hosts(web)
def emergency():
"""
Emergency rollback.
"""
with cd(PROJ_DIR):
run('git checkout stable')
migrate()
restart()