Skip to main content

kickstart_if_supervised

Function kickstart_if_supervised 

Source
pub fn kickstart_if_supervised() -> bool
Expand description

Start the daemon under launchd supervision, returning true only when it actually ran the service via launchctl kickstart.

The CLI calls this from spawn_daemon before falling back to a direct Command spawn. A direct spawn produces an unsupervised daemon: launchctl print reports state = not running and KeepAlive never fires, so a kill -9 is never restarted. Kickstarting an already bootstrapped service is what makes KeepAlive({SuccessfulExit=false}) genuinely protect the steady-state daemon.

Returns false — and the caller spawns directly — unless all hold:

  • the plist exists at ~/Library/LaunchAgents/<LABEL>.plist, and
  • its ProgramArguments binary equals the current exe (no stale path left behind by a moved/upgraded binary), and
  • the service is bootstrapped (launchctl print succeeds).

Those guards keep the first-ever run (no plist yet) and the post-upgrade run (plist still names the old binary) on the direct-spawn path. That spawned daemon’s own ensure_registered then rewrites the plist to the current exe and re-bootstraps, so the next spawn sees a fresh, loaded service and converges onto this supervised path.