-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
103 lines (67 loc) · 2.28 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
102
from fabric.api import *
env.hosts = ['mr.quibbl.es']
env.approot = "/var/quibbles/www"
env.prodhome = "/var/quibbles"
env.emailroot = "/var/quibbles/www/email"
def test():
local("nosetests tests/")
def pack(hash):
"""
Creates a clean copy of the code
"""
archivename = "%s.tar.gz" % hash
local("git archive --format=tar %s | gzip > /tmp/%s;" % (hash, archivename))
return archivename
def prepare(hash):
"""
Test and archive postosaurus.
"""
test()
pack(hash)
def upload(archive):
put('/tmp/%s' % archive, '/tmp/')
def untar(archive, hash):
with settings(warn_only=True):
with cd(env.prodhome):
sudo("rm -rf snapshots/%s" % hash)
sudo("mkdir snapshots/%s" % hash)
sudo("cd snapshots/%s; tar -xvf '/tmp/%s'" % (hash,archive))
def upload_untar(archive, hash):
upload(archive)
untar(archive, hash)
def switch(hash):
with cd(env.prodhome):
sudo("ln -s %s/snapshots/%s /tmp/live_tmp && sudo mv -Tf /tmp/live_tmp /var/quibbles/www" % (env.prodhome, hash))
with cd(env.approot):
sudo("cp prod/webapp/settings.py webapp/settings.py")
sudo("cp prod/email/settings.py email/config/settings.py")
sudo("ln -s /var/quibbles/run email/run")
sudo("ln -s /var/quibbles/logs email/logs")
sudo("rm -rf tests/")
def stop():
#TODO: this will break when there are multiple hosts, need to dynamically lookup uid and gid
#This assert makes sure I know when it breaks
assert len(env.hosts) == 1
with settings(warn_only=True):
with cd(env.emailroot):
sudo("apache2ctl stop")
sudo("lamson stop -ALL run/")
sudo("rm run/*")
def start():
#TODO: this will break when there are multiple hosts, need to dynamically lookup uid and gid
#This assert makes sure I know when it breaks
assert len(env.hosts) == 1
with settings(warn_only=True):
with cd(env.emailroot):
sudo("apache2ctl start")
sudo("lamson start -gid 1000 -uid 1000")
sudo("chown -R sean:sean %s" % env.prodhome)
def reboot():
stop()
start()
def deploy(hash):
test()
archive = pack(hash)
upload(archive)
untar(archive, hash)
switch(hash)