-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfabfile.py
75 lines (52 loc) · 1.85 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
import os.path
from fabric.api import *
from fabric.contrib.files import exists
from fabric.operations import get
from fabric import colors
REMOTE_REPO = '/var/local/agenda'
LOCAL_REPO = os.path.dirname(__file__)
def get_git_remote():
return env['host_string']
try: from local_fabfile import *
except: pass
paths = {
'repo': REMOTE_REPO,
'var': REMOTE_REPO + '/instance',
'sandbox': REMOTE_REPO + '/sandbox',
}
def install():
if not exists(REMOTE_REPO):
run("git init '%s'" % REMOTE_REPO)
git_remote = "%s:%s" % (get_git_remote(), REMOTE_REPO)
local("git push -f '%s' HEAD:incoming" % git_remote)
with cd(REMOTE_REPO):
run("git reset incoming --hard")
if not exists(paths['sandbox']):
run("virtualenv --no-site-packages '%(sandbox)s'" % paths)
run("echo '*' > '%(sandbox)s/.gitignore'" % paths)
run("%(sandbox)s/bin/pip install -r %(repo)s/requirements.txt" % paths)
instance = REMOTE_REPO + '/instance'
if not exists(instance):
run("mkdir -p '%s'" % instance)
def start():
run("/sbin/start-stop-daemon --start --background --chdir %(repo)s "
"--pidfile %(var)s/fcgi.pid --make-pidfile "
"--exec %(sandbox)s/bin/python %(repo)s/agenda.py fastcgi"
% paths, pty=False)
def stop():
run("/sbin/start-stop-daemon --stop --retry 3 --oknodo "
"--pidfile %(var)s/fcgi.pid" % paths)
def restart():
stop()
start()
def deploy():
install()
restart()
def backup():
from datetime import datetime
for name in ['agenda.db', 'database.log']:
filename = datetime.now().strftime('%Y-%m-%d-%H-%M') + '-' + name
local_path = os.path.join(LOCAL_REPO, 'backup', filename)
get('%(var)s/%(name)s' % dict(paths, name=name), local_path)
local("gzip '%s'" % local_path)
print colors.green('Backup successful')