"""Start the workspace services on container boot; keep SSH repair access on failure.""" from pathlib import Path import signal import subprocess import sys import time SERVICE = Path(__file__).with_name("service.py") stopping = False def request_stop(signum, frame): global stopping stopping = True def main(): signal.signal(signal.SIGTERM, request_stop) signal.signal(signal.SIGINT, request_stop) child = subprocess.Popen([sys.executable, str(SERVICE), "start"]) reported = False while not stopping: if child.poll() is not None and not reported: print(f"Model service exited ({child.returncode}); SSH remains available for repair. No automatic task replay.", flush=True) reported = True time.sleep(1) try: # Also stop a service the operator manually restarted while this # entrypoint was idle; the service command validates the recorded PID. subprocess.run([sys.executable, str(SERVICE), "stop"], timeout=90, check=False) if child.poll() is None: child.wait(timeout=5) except subprocess.TimeoutExpired: if child.poll() is None: child.kill() child.wait() return 0 if __name__ == "__main__": raise SystemExit(main())