Skip to main content

single_instance_check

Function single_instance_check 

Source
pub async fn single_instance_check(addr_file: Option<&Path>) -> StartupAction
Expand description

Perform the single-instance check at daemon startup.

Why: launchd’s KeepAlive { SuccessfulExit: false } respawns any non-zero exit, so a second daemon instance that fails to bind causes an endless respawn storm. Exiting 0 (when another healthy instance is detected) short- circuits this because SuccessfulExit: false means “restart only on non-zero exits” — exit 0 is treated as a voluntary clean shutdown. What: reads the http_addr discovery file; if it contains a reachable address whose /health responds with HTTP 200, returns StartupAction::ExitAlreadyRunning. Otherwise returns StartupAction::Proceed so the caller continues with normal bind. Errors reading the addr file or the network call are silently treated as “not running” (returns Proceed) so a missing or stale file never blocks a cold start. Test: integration — run trusty-memory serve --foreground twice in the same session and observe the second exits 0 without trying to bind; the unit tests in this module cover the decision logic.