-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
129 lines (104 loc) · 3.75 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
# coding: utf-8
import os
import shutil
from fabric.api import task, hosts, run, env, get, put, roles, local, prefix, cd
env.roledefs.update({
'router': ['[email protected]'],
'broker': ['[email protected]', '[email protected]',
'pipeliner': ['[email protected]'],
'web': ['[email protected]'],
})
@task
@roles('router', 'broker', 'pipeliner', 'web')
def stop_services():
if env.host == 'fgv.pypln.org':
service_name = 'wikipedia-broker'
elif env.host == 'wikipedia.pypln.org':
service_name = 'pypln-web'
elif env.host == 'hpc.pypln.org':
service_name = 'pypln-router pypln-pipeliner pypln-broker'
elif env.host == 'dirrj.pypln.org':
service_name = 'pypln-broker'
run('supervisorctl stop {}'.format(service_name))
@task
@roles('router', 'broker', 'pipeliner', 'web')
def remove_logs():
log_path = '/srv/pypln/logs/*'
if env.host == 'fgv.pypln.org':
log_path = '/srv/pypln/wikipedia/logs/*'
run('rm -rf {}'.format(log_path))
@task
@roles('router')
def start_router():
run('supervisorctl start pypln-router')
@task
@roles('pipeliner')
def start_pipeliner():
run('supervisorctl start pypln-pipeliner')
@task
@roles('broker')
def start_brokers():
service_name = 'pypln-broker'
if env.host == 'fgv.pypln.org':
service_name = 'wikipedia-broker'
run('supervisorctl start {}'.format(service_name))
@task
@roles('web')
def start_web():
run('supervisorctl start pypln-web')
def mkdir_if_not_exists(path):
if not os.path.exists(path):
os.mkdir(path)
@task
@roles('broker')
def download_broker_logs():
machine = env.host.split('.')[0]
mkdir_if_not_exists('logs')
try:
shutil.rmtree('logs/{}'.format(machine))
except OSError:
pass
mkdir_if_not_exists('logs/{}'.format(machine))
log_filename = '/srv/pypln/logs/pypln-broker.out'
if env.host == 'fgv.pypln.org':
log_filename = '/srv/pypln/wikipedia/logs/pypln-broker.out'
log_directory = os.path.dirname(log_filename)
log_filename = os.path.basename(log_filename)
log_tarball = 'broker-logs.tar.gz'
with cd(log_directory):
# first, old logs
run('rm -f {}'.format(log_tarball))
run('tar -zcf {} {}'.format(log_tarball, log_filename + '.*'))
remote_filename = os.path.join(log_directory, log_tarball)
get(remote_filename, 'logs/{}/{}'.format(machine, log_tarball))
run('rm -f {}'.format(log_tarball))
get(log_filename, 'logs/{}/'.format(machine))
local('cd logs/{0}/ && tar xfz {1} && cd ..'
.format(machine, log_tarball))
local('cat logs/{0}/*.out* > logs/{0}-broker.log'.format(machine))
local('rm -rf logs/{}/'.format(machine))
def upload_and_run_inside_django_env(filename, args=''):
put(filename, "/srv/pypln/project/web/pypln/web/")
with prefix("source /srv/pypln/project/bin/activate"), \
cd("/srv/pypln/project/web/pypln/web/"):
pythonpath = "/srv/pypln/project/web/pypln/web/apps/:$PYTHONPATH"
run("PYTHONPATH={} DJANGO_SETTINGS_MODULE=settings.production python "
"{} {}".format(pythonpath, filename, args))
@task
@roles('web')
def check_progress(corpus=""):
upload_and_run_inside_django_env('check_progress.py', corpus)
@task
@roles('web')
def calculate_pos_size(corpus="ptwp"):
upload_and_run_inside_django_env('calculate_pos_size.py', corpus)
@task
@roles('web')
def check_uploads(corpus="ptwp"):
upload_and_run_inside_django_env('check_uploads.py', corpus)
@task
@roles('web')
def export(corpus="ptwp"):
put('sqlite_corpus.py', "/srv/pypln/project/web/pypln/web/")
upload_and_run_inside_django_env('export_to_sqlite.py', corpus)