Expand description
Discovery file management for the single-instance daemon.
The daemon writes a JSON file to ~/.hyperdb/daemon.json containing its
PID and the hyperd endpoint. Clients read this file to locate the running
daemon, validating liveness via a TCP health check before trusting it.
Structs§
- Daemon
Info - Information written by the daemon so clients can discover and connect.
- Port
Scan - Port scan configuration: a base port and the number of ports to scan.
When
span == 1, the port is pinned (no scan). Used by the later port-scanning stage to discover or spawn a daemon across a range.
Enums§
- Probe
Result - Result of probing a single port: either our daemon, something else, or refused.
- Scan
Outcome - The outcome of scanning a port range for a running daemon or a free port to spawn on.
Functions§
- discover
- Read the discovery file and validate that the daemon is still alive.
Returns
Noneif no daemon is running (file missing, stale, or unreachable). - discovery_
file_ path - Returns the path to the discovery file.
- find_
running_ daemon - Discover a running daemon via the discovery file, or by scanning the configured
port range. Returns
Noneif no daemon is found in either place. - remove_
discovery_ file - Remove the discovery file (called during graceful shutdown).
- resolve_
port - Resolve the daemon health port from environment or default. Back-compat
wrapper for single-port callers; returns the base port from
resolve_port_scan. New code that needs scan-aware logic should callresolve_port_scandirectly. - resolve_
port_ scan - Resolve the daemon health port scan configuration from environment or default.
If
HYPERDB_DAEMON_PORTis set and valid, returns a pinned scan (span=1) at that exact port. Otherwise, returns the default base port with the full scan span. - scan_
for_ daemon - Scan the configured port range to find a running daemon or identify a free port.
If any port in the range answers identified-PING and returns valid STATUS, we return
Foundimmediately (first wins). Otherwise, we returnFreePortwith the first refused port encountered, orAllOccupiedif everything is in use. - state_
dir - Returns the directory used for daemon state files.
- write_
discovery_ file - Write the discovery file atomically (write-to-temp then rename).