Skip to main content

run

Function run 

Source
pub async fn run(
    cfg: ResolvedConfig,
    secret_key: SecretKey,
    config_path: Option<PathBuf>,
    reload_state: Arc<RuntimeReloadState>,
    node_metrics: Arc<Metrics>,
) -> Result<()>
Expand description

Build the endpoint, register handlers on a Router, spawn the metrics server and other background tasks, and run until a shutdown signal is received.

SIGHUP triggers a hot-reload of mutable config fields via RuntimeReloadState (see issue #236). Other signals (SIGINT/SIGTERM) trigger graceful shutdown.

The signal streams (SIGHUP, SIGTERM) are registered once before the select loop and reused on every iteration. Re-creating tokio::signal::unix::Signal each iteration would race with signal delivery: a SIGHUP that arrives while reload_runtime_config(..) is running would have nowhere to land if the future holding the Signal had already been dropped, and would be silently lost. The persistent stream queues the signal until the next recv() call (kernel-managed, with coalescing) so concurrent or rapidly-repeated signals are observed deterministically.

node_metrics is the registry /metrics serves. The caller builds it so that pre-runtime components (the OTLP exporter) count into the same registry.

secret_key is the node’s iroh identity. The caller loads it, so that the daemon entry point can build its JSON log formatter, which writes node_id on every event, before bring-up starts.