Skip to main content

Module daemon

Module daemon 

Source
Expand description

Daemon core — Unix-socket listener + request handler.

Public entry point: Daemon::run. The binary wrapper in src/bin/zero-headlessd.rs is thin glue: parse CLI flags, spawn a Daemon, wait on its shutdown handle.

§Shutdown paths (all equivalent)

  1. Request::Kill over the socket — set by /kill and the (M3) Telegram bot.
  2. SIGTERM from launchd / systemd.
  3. Shutdown handle held by the test harness.

All three funnel through a single shutdown_signal channel; the listener drops its accept loop on receive, open connections drain their in-flight request, and then the daemon exits with a zero status.

§Engine probe

Abstracted behind the EngineProbe trait so tests can inject a deterministic stub without standing up an HTTP server. Production uses HttpEngineProbe over zero_engine_client::HttpClient::health.

Structs§

AlwaysReachable
Always-reachable probe — convenient for tests that care about state + socket semantics and not about the probe machinery.
AlwaysUnreachable
Always-unreachable probe — for testing the honest “engine down” status path.
Config
Daemon configuration. Built by the binary’s main from CLI flags + defaults, and by tests via Config::for_test.
Daemon
In-memory daemon instance. The fields are Arc<Mutex<…>> so each accept-loop iteration can hand a handler task a clone without colouring everything Clone.
HttpEngineProbe
Production probe: calls GET /health via zero_engine_client::HttpClient. Kept outside the trait so the daemon core stays free of an HTTP-client dependency at the test boundary.
Shutdown
Handle returned from Daemon::spawn. Holding it keeps the daemon running; dropping it does not kill the daemon — tests that want a guaranteed shutdown should call Shutdown::shutdown and .await Shutdown::join.

Enums§

DaemonError

Traits§

EngineProbe
Abstract engine reachability probe. The daemon calls EngineProbe::probe on a schedule + on-demand before a /status reply that would otherwise return stale data.

Type Aliases§

ProbeFuture
Convenience alias for the engine probe’s future type. Pin<Box<dyn Future>> because async fn in dyn-compatible traits is still a rough edge; manual boxing keeps the dyn bound simple and the caller path explicit.