-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
134 lines (101 loc) · 3.97 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
from fabric.api import local, abort, run, cd, env, sudo
from fabric.utils import warn
from fabric.contrib.console import confirm
from fabric.contrib.files import exists
from datetime import date
import os
def dest_required(func):
def decorator(*args, **kwargs):
if not getattr(env, 'ready', False):
abort('Command must be after valid destination (i.e. fab prod start_fcgi)')
else:
return func(*args, **kwargs)
decorator.__doc__ = func.__doc__
return decorator
def prod():
'Points commands to production server'
env.hosts = ['[email protected]']
env.directory = '/home/tpetr/repos/muxlist/'
env.manage = os.path.join(env.directory, 'muxlist/manage.py')
env.socket = os.path.join(env.directory, 'bin/fastcgi.socket')
env.pidfile = os.path.join(env.directory, 'etc/django.pid')
env.nginx = os.path.join(env.directory, 'etc/nginx/')
env.target = 'prod'
env.ready = True
def local_setup():
'Points commands to local server'
env.hosts = ['localhost']
env.directory = os.path.abspath(os.path.dirname(__file__))
env.manage = os.path.join(env.directory, 'muxlist/manage.py')
env.socket = os.path.join(env.directory, 'bin/fastcgi.socket')
env.pidfile = os.path.join(env.directory, 'etc/django.pid')
env.nginx = os.path.join(env.directory, 'etc/nginx/')
env.target = 'local'
env.ready = True
@dest_required
def start_fcgi():
'Start the Django FastCGI daemon'
if exists(env.pidfile):
abort('PID file already exists (%(pidfile)s), fcgi already running?' % env)
else:
run('%(manage)s runfcgi method=threaded socket=%(socket)s pidfile=%(pidfile)s' % env)
run('chmod a+w %(socket)s' % env)
def restart_fcgi_local():
'Restart the Django FastCGI daemon locally'
local_setup()
if not os.path.exists(env.pidfile):
warn('PID file does not exist (%(pidfile)s), you may have to manually kill the fcgi process' % env)
else:
local('kill -term `cat %(pidfile)s`' % env)
local('rm %(pidfile)s' % env)
local('%(manage)s runfcgi method=threaded socket=%(socket)s pidfile=%(pidfile)s' % env)
local('chmod a+w %(socket)s' % env)
def start_fcgi_local():
'Start the Django FastCGI daemon locally'
local_setup()
if os.path.exists(env.pidfile):
abort('PID file already exists (%(pidfile)s), fcgi already running?' % env)
else:
local('%(manage)s runfcgi method=threaded socket=%(socket)s pidfile=%(pidfile)s' % env)
local('chmod a+w %(socket)s' % env)
def stop_fcgi_local():
'Stop the Django FastCGI daemon locally'
local_setup()
if not os.path.exists(env.pidfile):
warn('PID file does not exist (%(pidfile)s), you may have to manually kill the fcgi process' % env)
else:
local('kill -term `cat %(pidfile)s`' % env)
local('rm %(pidfile)s' % env)
@dest_required
def stop_fcgi():
'Stop the Django FastCGI daemon'
if not exists(env.pidfile):
warn('PID file does not exist (%(pidfile)s), you may have to manually kill the fcgi process' % env)
else:
run('kill -term `cat %(pidfile)s`' % env)
run('rm %(pidfile)s' % env)
@dest_required
def maintenance():
'Replace website with maintenance page'
if exists('%(nginx)s/%(target)s.conf' % env):
run('rm %(nginx)s/%(target)s.conf' % env)
run('ln -s %(nginx)s/%(target)s_maintenance.conf %(nginx)s/%(target)s.conf' % env)
sudo('nginx -s reload')
@dest_required
def online():
'Replace maintenance page with normal site'
if exists('%(nginx)s/%(target)s.conf' % env):
run('rm %(nginx)s/%(target)s.conf' % env)
run('ln -s %(nginx)s/%(target)s_django.conf %(nginx)s/%(target)s.conf' % env)
sudo('nginx -s reload')
@dest_required
def publish():
'Push changes to server'
maintenance()
stop_fcgi()
with cd(env.directory):
run('git stash > /dev/null')
run('git pull')
run('git stash pop > /dev/null')
start_fcgi()
online()