fix: prevent service crash-loop on port-in-use at startup
serve() now kills any stale process holding the configured port before uvicorn tries to bind. Prevents the crash-loop where systemd restarts muxplex but the old process is still holding port 8088 (observed: 2075+ restarts before manual intervention). New helper _kill_stale_port_holder(port): - Runs lsof -ti :<port> to find occupying PIDs - Sends SIGTERM to all foreign PIDs (skips own PID) - Waits 1 second for the port to free - Silently swallows all errors (missing lsof, permission denied) so a broken environment never prevents startup Also adds TimeoutStopSec=10 and KillMode=mixed to the systemd unit template so the old process gets SIGKILL'd if it does not exit on SIGTERM within 10 seconds — preventing the SIGTERM-ignored zombie scenario entirely.
This commit is contained in:
@@ -27,6 +27,8 @@ Type=simple
|
||||
ExecStart={exec_start}
|
||||
Restart=on-failure
|
||||
RestartSec=5s
|
||||
TimeoutStopSec=10
|
||||
KillMode=mixed
|
||||
Environment=PATH={safe_path}
|
||||
|
||||
[Install]
|
||||
|
||||
Reference in New Issue
Block a user