fix(gateway): exit code 75 on service restart so launchd relaunches

When the gateway receives SIGUSR1 (graceful restart via launchd_restart),
the SIGUSR1 handler calls request_restart(via_service=True) and the
gateway shuts down cleanly with exit code 0.

However, the generated launchd plist uses KeepAlive → SuccessfulExit →
false, meaning launchd only relaunches on *non-zero* exit codes.  A
clean exit(0) is treated as "successful, don't restart", so the
gateway stays down after /restart, /update, or SIGUSR1.

The systemd unit template already uses RestartForceExitStatus=75 for the
same scenario.  Mirror that convention: when _restart_via_service is
True, raise SystemExit(75) so launchd's SuccessfulExit=false policy
triggers a relaunch.

Closes #28135
This commit is contained in:
zccyman 2026-05-18 20:03:13 -07:00 committed by Teknium
parent c5cafd3847
commit 5987b24314

View file

@ -17346,6 +17346,19 @@ async def start_gateway(config: Optional[GatewayConfig] = None, replace: bool =
)
return False # → sys.exit(1) in the caller
# When the gateway is restarting via the service manager (SIGUSR1 →
# launchd_restart or /restart / /update commands), exit with code 75 so
# that launchd's ``KeepAlive → SuccessfulExit → false`` policy treats
# the exit as *unsuccessful* and relaunches the service. This mirrors
# the systemd ``RestartForceExitStatus=75`` convention already used by
# the systemd unit template.
if runner._restart_via_service:
logger.info(
"Exiting with code 75 (service-restart requested) so "
"launchd KeepAlive relaunches the gateway."
)
raise SystemExit(75)
return True