This repository has been archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
fabfile.py
162 lines (128 loc) · 5.48 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"""
Support for www service installation and management.
"""
from fabric.api import run, settings, env, put, sudo
from os import path
from twisted.python.util import sibpath
from braid import authbind, git, cron, archive, pip
from braid.twisted import service
from braid.debian import equivs
from braid.tasks import addTasks
from braid.utils import confirm
from braid import config
__all__ = ['config']
class TwistedWeb(service.Service):
def task_install(self):
"""
Install t-web, a Twisted Web based server.
"""
# Bootstrap a new service environment
self.bootstrap()
# Add to www-data group. Mailman depends on this.
sudo('/usr/sbin/usermod -a -g www-data -G t-web {}'.format(self.serviceUser))
# Setup authbind
authbind.allow(self.serviceUser, 80)
authbind.allow(self.serviceUser, 443)
# Install httpd equiv, so apt doesn't try to install apache ever
equivs.installEquiv(self.serviceName, 'httpd')
with settings(user=self.serviceUser):
pip.install('txsni', python='pypy')
run('/bin/ln -nsf {}/start {}/start'.format(self.configDir, self.binDir))
run('/bin/ln -nsf {}/start-maintenance {}/start-maintenance'.format(self.configDir, self.binDir))
self.update()
cron.install(self.serviceUser, '{}/crontab'.format(self.configDir))
run('/bin/mkdir -p ~/data')
if env.get('installPrivateData'):
self.task_installSSLKeys()
run('/usr/bin/touch {}/production'.format(self.configDir))
else:
run('/bin/rm -f {}/production'.format(self.configDir))
def task_installSSLKeys(self):
"""
Install SSL keys.
"""
cert = sibpath(__file__, 'twistedmatrix.com.crt')
with settings(user=self.serviceUser):
run('mkdir -p ~/ssl')
for cert in ['www.twistedmatrix.com.pem',
'buildbot.twistedmatrix.com.pem']:
fullpath = sibpath(__file__, cert)
if path.exists(fullpath):
put(fullpath, '~/ssl/' + cert, mode=0600)
run('ln -s ~/ssl/www.twistedmatrix.com.pem '
'~/ssl/twistedmatrix.com.pem')
run('ln -s ~/ssl/www.twistedmatrix.com.pem ~/ssl/DEFAULT.pem')
def update(self):
"""
Update config.
"""
with settings(user=self.serviceUser):
git.push(path.dirname(__file__), self.configDir)
def task_update(self):
"""
Update config and restart.
"""
self.update()
self.task_restart()
def task_dump(self, dump):
"""
Dump non-versioned resources.
"""
with settings(user=self.serviceUser):
archive.dump({
'data': 'data',
}, dump)
def task_restore(self, dump):
"""
Resotre non-versioned resources.
"""
msg = 'All non-versioned web resources will be replaced with the backup.'
if confirm(msg):
with settings(user=self.serviceUser):
archive.restore({
'data': 'data',
}, dump)
def task_startMaintenanceSite(self):
"""
Start maintenance site.
"""
with settings(user=self.serviceUser):
run('{}/start-maintenance'.format(self.binDir))
def task_uploadRelease(self, release, releasesTarball):
"""
Upload a relase.
It expects a tarball containing the following files:
- Twisted<Subproject>-<release>.tar.bz2
- Twisted-<release>.<ext> for all source/windows installers
- twisted-<release>-<hash>.txt for md5 and sha512
- doc - for narative documentation
- api - for api documents
@param release: Release version.
@param releasesTarball: Tarball with release tarballs and documentation
"""
apiVersion = '.'.join(release.split('.')[:2])
distPaths = {}
for ext in ['.tar.bz2',
'-cp27-none-win32.whl', '.win32-py2.7.exe', '.win32-py2.7.msi',
'.win-amd64-py2.7.msi', '.win-amd64-py2.7.exe', '-cp27-none-win_amd64.whl']:
tarball = 'Twisted-{}{}'.format(release, ext)
distPaths[tarball] = 'data/releases/Twisted/{}/{}'.format(apiVersion, tarball)
for subproject in ['Core', 'Conch', 'Lore', 'Mail', 'Names', 'News', 'Pair', 'Runner', 'Web', 'Words']:
tarball = 'Twisted{}-{}.tar.bz2'.format(subproject, release)
distPaths[tarball] = 'data/releases/{}/{}/{}'.format(subproject, apiVersion, tarball)
distPaths['doc'] = 'data/documentation/{}'.format(release)
distPaths['api'] = 'data/documentation/{}/api'.format(release)
for hash in ['md5sums', 'shasums']:
hashFile = 'twisted-{}-{}.txt'.format(release,hash)
distPaths[hashFile] = 'data/releases/{}'.format(hashFile)
directories = [path.dirname(file) for file in distPaths.values()]
with settings(user=self.serviceUser):
run('/bin/mkdir -p {}'.format(' '.join(set(directories))))
archive.restore(distPaths, releasesTarball)
def task_updateCurrentDocumentation(self, release):
"""
Update the current link for documentation
"""
with settings(user=self.serviceUser):
run('/bin/ln -nsf {} data/documentation/current'.format(release))
addTasks(globals(), TwistedWeb('t-web').getTasks())