-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
87 lines (58 loc) · 2.02 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
# coding: utf-8
import os
from fabric.api import run, env, roles, prefix, put, cd
from fabric.contrib.files import exists
env.roledefs = {
'develop': [
],
}
ENV_PATH = '/home/jummy/workspace/env'
ACTIVE_FILE_PATH = os.path.join(ENV_PATH, 'bin/activate')
PYPI_INDEX = 'http://111.230.25.51:8080/simple/'
def pip(package, version=None):
command = 'pip install -i {pypi} --trusted-host=111.230.25.51 '.format(pypi=PYPI_INDEX)
if version:
command = command + '{package}=={version}'.format(package=package, version=version)
else:
command = command + package
run(command)
@roles('develop')
def deploy(version):
ensure_venv()
install(version)
upload_env()
upload_supervisord_conf()
run_supervisord()
def install(version):
with prefix('source %s' % ACTIVE_FILE_PATH):
pip('selfblog', version)
def ensure_venv():
if not exists(ACTIVE_FILE_PATH):
run('virtualenv {}'.format(ENV_PATH))
def ensure_supervisord():
with prefix('source %s' % ACTIVE_FILE_PATH):
result = run('which supervisord', warn_only=True)
if 'no supervisord' in result:
pip('supervisor')
def upload_env():
put('selfblog/.env', '{}/.env'.format(ENV_PATH))
def upload_supervisord_conf():
put('conf/supervisord.conf', '{}/supervisord.conf'.format(ENV_PATH))
def run_supervisord():
ensure_supervisord()
result = run('ps aux|grep supervisord | grep -v grep', warn_only=True)
if result:
shutdown_supervisord()
# return restart_supervisord()
with prefix('source %s' % ACTIVE_FILE_PATH):
with cd(ENV_PATH):
run('supervisord -c supervisord.conf')
def restart_supervisord():
with prefix('source %s' % ACTIVE_FILE_PATH):
with cd(ENV_PATH):
run('supervisorctl -c supervisord.conf restart all')
def shutdown_supervisord():
with prefix('source %s' % ACTIVE_FILE_PATH):
with cd(ENV_PATH):
run('supervisorctl -c supervisord.conf shutdown')