Module restart
Expand description
Post-update self-respawn for bare (unsupervised) processes.
When the dashboard applies an upgrade with auto-restart on a process that has
no supervisor (no systemd/launchd), the gateway calls request_respawn and
triggers the daemon’s graceful shutdown (SIGTERM). After the daemon loop
tears down — which releases the listening port — main calls
respawn_if_requested, which launches a detached child running the
freshly-swapped on-disk binary; the parent then exits.
Doing the spawn after teardown (rather than from the gateway task) avoids a port-bind race: by the time the child starts, the old listener is gone.
The launch command (executable path + argv) is captured at startup via
record_launch, before any binary swap: on Linux current_exe()
resolves to a "…/zeroclaw (deleted)" path once the running inode is
unlinked by the swap, which is not spawnable.
Functions§
- record_
launch - Capture the launch executable + args once, at startup (before any upgrade swaps the binary). Idempotent — later calls are ignored.
- request_
respawn - Request a self-respawn after the daemon shuts down. The caller is expected to also trigger the daemon’s graceful shutdown so the loop tears down first.
- request_
shutdown - Request a graceful daemon shutdown in-process (cross-platform). Pairs with a
prior
request_respawnto turn the shutdown into a self-restart. - respawn_
if_ requested - If a respawn was requested, launch a detached child running the captured launch command (now the new on-disk binary), and return its PID.
- respawn_
requested - Whether a self-respawn was requested.
- shutdown_
notify - The global in-process shutdown trigger, for the daemon loop to await.