Skip to main content

Module restart

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_respawn to 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.