-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
59 lines (54 loc) · 2.15 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
from fabric.api import (
cd,
env,
local,
put,
require,
run,
sudo,
)
env.project_name = 'photasm'
env.project_root = '/usr/local/webapps/'
def deploy():
"""\
Deploy the latest version of the site to the servers.
"""
# Options for specifying env requirements:
# Command line, per task: fab deploy:hosts="host1;host2"
# Command line, globally: fab --hosts host1,host2 deploy
require('hosts')
require('project_root') # e.g. /usr/local/webapps/
require('project_name')
import time
env.release = time.strftime('%Y%m%d%H%M%S')
local('hg archive --type tgz '
'/tmp/%(project_name)s-%(release)s.tar.gz' % env)
put('/tmp/%(project_name)s-%(release)s.tar.gz' % env,
'/tmp/%(project_name)s-%(release)s.tar.gz' % env)
with cd(env.project_root):
sudo('tar -xzf /tmp/%(project_name)s-%(release)s.tar.gz' % env)
sudo('if [[ -d %(project_root)s/%(project_name)s ]]; then '
'mv %(project_root)s/%(project_name)s '
'%(project_root)s/%(project_name)s-%(release)s.bak;'
'fi' % env)
sudo('mv %(project_root)s/%(project_name)s-%(release)s '
'%(project_root)s/%(project_name)s' % env)
sudo('if [[ -f %(project_root)s/%(project_name)s-%(release)s.bak/'
'settings_local.py ]]; then '
'mv %(project_root)s/%(project_name)s-%(release)s.bak/'
'settings_local.py '
'%(project_root)s/%(project_name)s/;'
'else '
'cp %(project_root)s/%(project_name)s/settings_local.py.template '
'%(project_root)s/%(project_name)s/settings_local.py; '
'fi' % env)
sudo('if [[ -d %(project_root)s/%(project_name)s-%(release)s.bak ]]; '
'then '
'rm -rf %(project_root)s/%(project_name)s-%(release)s.bak;'
'fi' % env)
sudo('chown -R root:www-admin %(project_root)s/%(project_name)s' % env)
sudo('chmod -R g+w %(project_root)s/%(project_name)s' % env)
run('rm /tmp/%(project_name)s-%(release)s.tar.gz' % env)
local('rm /tmp/%(project_name)s-%(release)s.tar.gz' % env)
sudo('if ( ps -ef | grep apache2 | grep -v grep ); then '
'apache2ctl -k graceful; fi')