Repository navigation
Expand file tree
/
Copy pathstart_server.py
More file actions
38 lines (32 loc) · 1.41 KB
/
Copy pathstart_server.py
File metadata and controls
38 lines (32 loc) · 1.41 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
import sys, os, threading, time, subprocess
from pegasus.ui.web.backend.app import create_app
from pegasus.core.config import port, host, base_url
app = create_app()
def run():
print(f"Starting Pegasus Phantom Menace on port {port()}...")
app.run(host=host(), port=port(), debug=False, use_reloader=False, threaded=True)
# The server thread must NOT be a daemon: the desktop shell spawns this
# script and waits on the health endpoint, so if the interpreter exits the
# daemon thread dies with it and the console loses its backend seconds after
# launch. A non-daemon thread keeps the process alive, and join() makes the
# intent explicit.
server = threading.Thread(target=run, daemon=False)
server.start()
print(f"Server running at {base_url()}/")
time.sleep(3)
try:
import urllib.request
resp = urllib.request.urlopen(f"{base_url()}/api/health", timeout=5)
print("Health check:", resp.status)
except Exception as e:
print("Check error:", e)
# Block until the server stops.
# C2 autostart. Deliberately NOT inside create_app(): starting a second
# WSGI listener while the first app is still being constructed stops the
# backend serving. This runs once the socket is already listening.
try:
from pegasus.ui.web.backend import c2_routes as _c2_routes
_c2_routes.maybe_autostart()
except Exception as _exc: # autostart must never take the console down
print(f"C2 autostart skipped: {_exc}")
server.join()