forked from adamlaska/boulder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstartservers.py
More file actions
284 lines (260 loc) · 11.5 KB
/
startservers.py
File metadata and controls
284 lines (260 loc) · 11.5 KB
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
import atexit
import collections
import os
import shutil
import signal
import subprocess
import sys
import tempfile
import threading
import time
from helpers import waithealth, waitport, config_dir, CONFIG_NEXT
Service = collections.namedtuple('Service', ('name', 'debug_port', 'grpc_addr', 'cmd', 'deps'))
SERVICES = (
Service('sd-test-srv',
53, None,
('./bin/sd-test-srv', '--listen', ':53'),
None),
Service('boulder-remoteva-a',
8011, 'va1.boulder:9097',
('./bin/boulder-remoteva', '--config', os.path.join(config_dir, 'va-remote-a.json')),
('sd-test-srv',)),
Service('boulder-remoteva-b',
8012, 'va1.boulder:9098',
('./bin/boulder-remoteva', '--config', os.path.join(config_dir, 'va-remote-b.json')),
('sd-test-srv',)),
Service('boulder-sa-1',
8003, 'sa1.boulder:9095',
('./bin/boulder-sa', '--config', os.path.join(config_dir, 'sa.json'), '--addr', 'sa1.boulder:9095', '--debug-addr', ':8003'),
('sd-test-srv',)),
Service('boulder-sa-2',
8103, 'sa2.boulder:9095',
('./bin/boulder-sa', '--config', os.path.join(config_dir, 'sa.json'), '--addr', 'sa2.boulder:9095', '--debug-addr', ':8103'),
('sd-test-srv',)),
Service('ct-test-srv',
4500, None,
('./bin/ct-test-srv', '--config', 'test/ct-test-srv/ct-test-srv.json'),
None),
Service('boulder-publisher-1',
8009, 'publisher1.boulder:9091',
('./bin/boulder-publisher', '--config', os.path.join(config_dir, 'publisher.json'), '--addr', 'publisher1.boulder:9091', '--debug-addr', ':8009'),
('sd-test-srv',)),
Service('boulder-publisher-2',
8109, 'publisher2.boulder:9091',
('./bin/boulder-publisher', '--config', os.path.join(config_dir, 'publisher.json'), '--addr', 'publisher2.boulder:9091', '--debug-addr', ':8109'),
('sd-test-srv',)),
Service('mail-test-srv',
9380, None,
('./bin/mail-test-srv', '--closeFirst', '5', '--cert', 'test/mail-test-srv/localhost/cert.pem', '--key', 'test/mail-test-srv/localhost/key.pem'),
None),
Service('ocsp-responder',
8005, None,
('./bin/ocsp-responder', '--config', os.path.join(config_dir, 'ocsp-responder.json')),
None),
Service('boulder-va-1',
8004, 'va1.boulder:9092',
('./bin/boulder-va', '--config', os.path.join(config_dir, 'va.json'), '--addr', 'va1.boulder:9092', '--debug-addr', ':8004'),
('sd-test-srv', 'boulder-remoteva-a', 'boulder-remoteva-b')),
Service('boulder-va-2',
8104, 'va2.boulder:9092',
('./bin/boulder-va', '--config', os.path.join(config_dir, 'va.json'), '--addr', 'va2.boulder:9092', '--debug-addr', ':8104'),
('sd-test-srv', 'boulder-remoteva-a', 'boulder-remoteva-b')),
Service('boulder-ca-a',
8001, 'ca1.boulder:9093',
('./bin/boulder-ca', '--config', os.path.join(config_dir, 'ca-a.json'), '--ca-addr', 'ca1.boulder:9093', '--ocsp-addr', 'ca1.boulder:9096', '--debug-addr', ':8001'),
('sd-test-srv', 'boulder-sa-1', 'boulder-sa-2')),
Service('boulder-ca-b',
8101, 'ca2.boulder:9093',
('./bin/boulder-ca', '--config', os.path.join(config_dir, 'ca-b.json'), '--ca-addr', 'ca2.boulder:9093', '--ocsp-addr', 'ca2.boulder:9096', '--debug-addr', ':8101'),
('sd-test-srv', 'boulder-sa-1', 'boulder-sa-2')),
Service('akamai-test-srv',
6789, None,
('./bin/akamai-test-srv', '--listen', 'localhost:6789', '--secret', 'its-a-secret'),
None),
Service('akamai-purger',
9666, None,
('./bin/akamai-purger', '--config', os.path.join(config_dir, 'akamai-purger.json')),
('akamai-test-srv',)),
Service('ocsp-updater',
8006, None,
('./bin/ocsp-updater', '--config', os.path.join(config_dir, 'ocsp-updater.json')),
('boulder-ca-a', 'boulder-ca-b')),
Service('boulder-ra-1',
8002, 'ra1.boulder:9094',
('./bin/boulder-ra', '--config', os.path.join(config_dir, 'ra.json'), '--addr', 'ra1.boulder:9094', '--debug-addr', ':8002'),
('sd-test-srv', 'boulder-sa-1', 'boulder-sa-2', 'boulder-ca-a', 'boulder-ca-b', 'boulder-va-1', 'boulder-va-2', 'akamai-purger', 'boulder-publisher-1', 'boulder-publisher-2')),
Service('boulder-ra-2',
8102, 'ra2.boulder:9094',
('./bin/boulder-ra', '--config', os.path.join(config_dir, 'ra.json'), '--addr', 'ra2.boulder:9094', '--debug-addr', ':8102'),
('sd-test-srv', 'boulder-sa-1', 'boulder-sa-2', 'boulder-ca-a', 'boulder-ca-b', 'boulder-va-1', 'boulder-va-2', 'akamai-purger', 'boulder-publisher-1', 'boulder-publisher-2')),
Service('bad-key-revoker',
8020, None,
('./bin/bad-key-revoker', '--config', os.path.join(config_dir, 'bad-key-revoker.json')),
('sd-test-srv', 'boulder-ra-1', 'boulder-ra-2', 'mail-test-srv')),
Service('nonce-service-taro',
8111, 'nonce1.boulder:9101',
('./bin/nonce-service', '--config', os.path.join(config_dir, 'nonce.json'), '--addr', 'nonce1.boulder:9101', '--debug-addr', ':8111', '--prefix', 'taro'),
('sd-test-srv',)),
Service('nonce-service-zinc',
8112, 'nonce2.boulder:9101',
('./bin/nonce-service', '--config', os.path.join(config_dir, 'nonce.json'), '--addr', 'nonce2.boulder:9101', '--debug-addr', ':8112', '--prefix', 'zinc'),
('sd-test-srv',)),
Service('boulder-wfe2',
4001, None,
('./bin/boulder-wfe2', '--config', os.path.join(config_dir, 'wfe2.json')),
('sd-test-srv', 'boulder-ra-1', 'boulder-ra-2', 'boulder-sa-1', 'boulder-sa-2', 'nonce-service-taro', 'nonce-service-zinc')),
Service('log-validator',
8016, None,
('./bin/log-validator', '--config', os.path.join(config_dir, 'log-validator.json')),
None),
)
def _service_toposort(services):
"""Yields Service objects in topologically sorted order.
No service will be yielded until every service listed in its deps value
has been yielded.
"""
ready = set([s for s in services if not s.deps])
blocked = set(services) - ready
done = set()
while ready:
service = ready.pop()
yield service
done.add(service.name)
new = set([s for s in blocked if all([d in done for d in s.deps])])
ready |= new
blocked -= new
if blocked:
print("WARNING: services with unsatisfied dependencies:")
for s in blocked:
print(s.name, ":", s.deps)
raise(Exception("Unable to satisfy service dependencies"))
processes = []
# NOTE(@cpu): We manage the challSrvProcess separately from the other global
# processes because we want integration tests to be able to stop/start it (e.g.
# to run the load-generator).
challSrvProcess = None
def setupHierarchy():
"""Set up the issuance hierarchy. Must have called install() before this."""
e = os.environ.copy()
e.setdefault("GOBIN", "%s/bin" % os.getcwd())
try:
subprocess.check_output(["go", "run", "test/cert-ceremonies/generate.go"], env=e)
except subprocess.CalledProcessError as e:
print(e.output)
raise
def install(race_detection):
# Pass empty BUILD_TIME and BUILD_ID flags to avoid constantly invalidating the
# build cache with new BUILD_TIMEs, or invalidating it on merges with a new
# BUILD_ID.
cmd = "/usr/bin/make GO_BUILD_FLAGS='-tags \"integration\"' "
if race_detection:
cmd = "/usr/bin/make GO_BUILD_FLAGS='-race -tags \"integration\"'"
return subprocess.call(cmd, shell=True) == 0
def run(cmd, fakeclock):
e = os.environ.copy()
e.setdefault("GORACE", "halt_on_error=1")
if fakeclock:
e.setdefault("FAKECLOCK", fakeclock)
p = subprocess.Popen(cmd, env=e)
p.cmd = cmd
return p
def start(fakeclock):
"""Return True if everything builds and starts.
Give up and return False if anything fails to build, or dies at
startup. Anything that did start before this point can be cleaned
up explicitly by calling stop(), or automatically atexit.
"""
signal.signal(signal.SIGTERM, lambda _, __: stop())
signal.signal(signal.SIGINT, lambda _, __: stop())
# Start the pebble-challtestsrv first so it can be used to resolve DNS for
# gRPC.
startChallSrv()
# Processes are in order of dependency: Each process should be started
# before any services that intend to send it RPCs. On shutdown they will be
# killed in reverse order.
for service in _service_toposort(SERVICES):
print("Starting service", service.name)
try:
global processes
p = run(service.cmd, fakeclock)
processes.append(p)
if service.grpc_addr is not None:
waithealth(' '.join(p.args), service.grpc_addr)
else:
if not waitport(service.debug_port, ' '.join(p.args), perTickCheck=check):
return False
except Exception as e:
print("Error starting service %s: %s" % (service.name, e))
return False
print("All servers running. Hit ^C to kill.")
return True
def check():
"""Return true if all started processes are still alive.
Log about anything that died. The pebble-challtestsrv is not considered when
checking processes.
"""
global processes
busted = []
stillok = []
for p in processes:
if p.poll() is None:
stillok.append(p)
else:
busted.append(p)
if busted:
print("\n\nThese processes exited early (check above for their output):")
for p in busted:
print("\t'%s' with pid %d exited %d" % (p.cmd, p.pid, p.returncode))
processes = stillok
return not busted
def startChallSrv():
"""
Start the pebble-challtestsrv and wait for it to become available. See also
stopChallSrv.
"""
global challSrvProcess
if challSrvProcess is not None:
raise(Exception("startChallSrv called more than once"))
# NOTE(@cpu): We specify explicit bind addresses for -https01 and
# --tlsalpn01 here to allow HTTPS HTTP-01 responses on 5001 for on interface
# and TLS-ALPN-01 responses on 5001 for another interface. The choice of
# which is used is controlled by mock DNS data added by the relevant
# integration tests.
challSrvProcess = run([
'pebble-challtestsrv',
'--defaultIPv4', os.environ.get("FAKE_DNS"),
'-defaultIPv6', '',
'--dns01', ':8053,:8054',
'--management', ':8055',
'--http01', '10.77.77.77:5002',
'-https01', '10.77.77.77:5001',
'--tlsalpn01', '10.88.88.88:5001'],
None)
# Wait for the pebble-challtestsrv management port.
if not waitport(8055, ' '.join(challSrvProcess.args)):
return False
def stopChallSrv():
"""
Stop the running pebble-challtestsrv (if any) and wait for it to terminate.
See also startChallSrv.
"""
global challSrvProcess
if challSrvProcess is None:
return
if challSrvProcess.poll() is None:
challSrvProcess.send_signal(signal.SIGTERM)
challSrvProcess.wait()
challSrvProcess = None
@atexit.register
def stop():
# When we are about to exit, send SIGTERM to each subprocess and wait for
# them to nicely die. This reflects the restart process in prod and allows
# us to exercise the graceful shutdown code paths.
global processes
for p in reversed(processes):
if p.poll() is None:
p.send_signal(signal.SIGTERM)
p.wait()
processes = []
# Also stop the challenge test server
stopChallSrv()