c0re: emit /var/lib/hyperhive/agent-ports.json on meta sync for gateway (#15)

This commit is contained in:
damocles 2026-05-31 12:58:40 +02:00 committed by Mara
commit e197efd3a6
3 changed files with 178 additions and 0 deletions

View file

@ -101,6 +101,20 @@ pub async fn sync_agents(
let topology_changed = crate::topology::reconcile(&agent_names)
.with_context(|| format!("reconcile {}", crate::topology::topology_path().display()))?;
// Refresh /var/lib/hyperhive/agent-ports.json so the hive-gateway
// nginx sees the new agent set (#15 / #740). The file is the
// single source of truth for which agents the gateway proxies to,
// since the gateway container lives in system config and can't be
// rebuilt from meta-flake events. Atomic write (tmp + rename) so
// a partial write never trips the gateway's read.
if let Err(e) = crate::agent_ports::write(&agent_names) {
// Best-effort: a failed write doesn't block the meta-flake
// regen + container ops that follow. The gateway falls back
// to whatever map is currently on disk (or an empty map on
// first boot, meaning no per-agent routing yet).
tracing::warn!(error = ?e, "agent_ports::write failed (non-fatal)");
}
if initial {
git(&dir, &["init", "--initial-branch=main"]).await?;
}