35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
"""Run the app adapter and isolated Business service with shared lifecycle."""
|
|
import os
|
|
import signal
|
|
import subprocess
|
|
import time
|
|
children = []
|
|
stopping = False
|
|
|
|
def shutdown(*_):
|
|
global stopping
|
|
stopping = True
|
|
|
|
signal.signal(signal.SIGTERM, shutdown)
|
|
signal.signal(signal.SIGINT, shutdown)
|
|
try:
|
|
children.append(subprocess.Popen(['python3', 'business/server.py'], env={**os.environ,
|
|
'JWB_HOST':'127.0.0.1', 'JWB_PORT':'4310', 'JWB_BASE_PATH':'/business-demo',
|
|
'JWB_DATA_DIR':'/data/business', 'JWB_AUTH_MODE':'enforce',
|
|
'JWB_COOKIE_SECURE':'0', 'JWB_ARCHIPELAGO':'1'}))
|
|
children.append(subprocess.Popen(['python3', 'server.py']))
|
|
while not stopping and all(child.poll() is None for child in children): time.sleep(0.5)
|
|
finally:
|
|
for child in children:
|
|
if child.poll() is None: child.terminate()
|
|
# Give both services the same grace period, then reap resistant children.
|
|
deadline = time.monotonic() + 5
|
|
for child in children:
|
|
try:
|
|
child.wait(timeout=max(0, deadline - time.monotonic()))
|
|
except subprocess.TimeoutExpired:
|
|
child.kill()
|
|
for child in children:
|
|
child.wait(timeout=5)
|
|
raise SystemExit(0 if stopping else 1)
|