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
118 lines (92 loc) · 3.55 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
"""
Support for www service installation and management.
"""
from fabric.api import run, settings, env, put, abort, sudo
from fabric.contrib import files
from os import path
from twisted.python.util import sibpath
from braid import authbind, git, cron, archive
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):
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, key=sibpath(__file__, 'twistedmatrix.com.key'), cert=sibpath(__file__, 'twistedmatrix.com.crt')):
"""
Install SSL keys.
@param key: Local path to key
@param cert: Local path to cert
"""
with settings(user=self.serviceUser):
run('mkdir -p ~/ssl')
if path.exists(key):
put(key, '~/ssl/twistedmatrix.com.key', mode=0600)
elif not files.exists('~/ssl/twistedmatrix.com.key'):
abort('Missing SSL key.')
if path.exists(cert):
put(cert, '~/ssl/twistedmatrix.com.crt')
elif not files.exists('~/ssl/twistedmatrix.com.crt'):
abort('Missing SSL certificate.')
def update(self):
"""
Update config.
"""
with settings(user=self.serviceUser):
git.branch('https://github.com/twisted-infra/t-web', 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))
addTasks(globals(), TwistedWeb('t-web').getTasks())