Spaces:
Paused
Paused
BPEL Bot commited on
Commit ·
c6b0120
1
Parent(s): bad3400
Start prodserver and worker via helper script
Browse files- docker-entrypoint.sh +3 -2
- scripts/run_serve_and_worker.py +38 -0
docker-entrypoint.sh
CHANGED
|
@@ -47,5 +47,6 @@ cd "$RUNTIME_DIR"
|
|
| 47 |
log "Working directory: $(pwd)"
|
| 48 |
touch db.sqlite3 || true
|
| 49 |
|
| 50 |
-
log "Starting oTree
|
| 51 |
-
|
|
|
|
|
|
| 47 |
log "Working directory: $(pwd)"
|
| 48 |
touch db.sqlite3 || true
|
| 49 |
|
| 50 |
+
log "Starting oTree services on 0.0.0.0:${PORT_VALUE}"
|
| 51 |
+
export PORT="$PORT_VALUE"
|
| 52 |
+
exec python scripts/run_serve_and_worker.py
|
scripts/run_serve_and_worker.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import os
|
| 3 |
+
import signal
|
| 4 |
+
import subprocess
|
| 5 |
+
import sys
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def main() -> int:
|
| 9 |
+
port = os.environ.get("PORT", "7860")
|
| 10 |
+
server_cmd = [
|
| 11 |
+
"otree",
|
| 12 |
+
"prodserver1of2",
|
| 13 |
+
f"0.0.0.0:{port}",
|
| 14 |
+
]
|
| 15 |
+
worker_cmd = [
|
| 16 |
+
"otree",
|
| 17 |
+
"prodserver2of2",
|
| 18 |
+
]
|
| 19 |
+
|
| 20 |
+
server_proc = subprocess.Popen(server_cmd)
|
| 21 |
+
worker_proc = subprocess.Popen(worker_cmd)
|
| 22 |
+
|
| 23 |
+
def shutdown(signum, frame):
|
| 24 |
+
worker_proc.terminate()
|
| 25 |
+
server_proc.terminate()
|
| 26 |
+
|
| 27 |
+
signal.signal(signal.SIGTERM, shutdown)
|
| 28 |
+
signal.signal(signal.SIGINT, shutdown)
|
| 29 |
+
|
| 30 |
+
# wait for worker first (since it will block until stop)
|
| 31 |
+
worker_return = worker_proc.wait()
|
| 32 |
+
server_proc.terminate()
|
| 33 |
+
server_proc.wait()
|
| 34 |
+
return worker_return
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
if __name__ == "__main__":
|
| 38 |
+
sys.exit(main())
|