feat: group host-side /var/lib/hyperhive state into db/ forge/ matrix/ run/ subdirs with startup migration

This commit is contained in:
damocles 2026-06-05 22:48:10 +02:00 committed by mara
commit 14c7b0d406
15 changed files with 261 additions and 51 deletions

View file

@ -1,4 +1,4 @@
//! `/var/lib/hyperhive/agent-ports.json` writer — flat map of
//! `/var/lib/hyperhive/run/agent-ports.json` writer — flat map of
//! agent name → TCP web port. Written alongside `agents.conf` on
//! every topology change. JSON shape, port derivation (FNV-1a hash),
//! atomicity, and manager exclusion: `docs/gateway.md::Agent port map`.
@ -10,11 +10,9 @@ use anyhow::{Context, Result};
use crate::lifecycle::{self, MANAGER_NAME};
const HOST_PORTS_PATH: &str = "/var/lib/hyperhive/agent-ports.json";
#[must_use]
pub fn host_ports_path() -> PathBuf {
PathBuf::from(HOST_PORTS_PATH)
crate::paths::agent_ports_file()
}
/// Compute the agent-port map for the given logical agent names.
@ -34,7 +32,7 @@ pub fn build_map(names: &[String]) -> BTreeMap<String, u16> {
}
/// Render the map as pretty-printed JSON. Pretty so a human peek at
/// `cat /var/lib/hyperhive/agent-ports.json` shows one row per agent
/// `cat /var/lib/hyperhive/run/agent-ports.json` shows one row per agent
/// — keeps the file readable without a separate jq step.
fn render(map: &BTreeMap<String, u16>) -> String {
// BTreeMap → serde_json::to_string_pretty preserves key order,
@ -44,7 +42,7 @@ fn render(map: &BTreeMap<String, u16>) -> String {
}
/// Atomically write the JSON for `names` to
/// `/var/lib/hyperhive/agent-ports.json`. Writes via a sibling
/// `/var/lib/hyperhive/run/agent-ports.json`. Writes via a sibling
/// `<path>.tmp` + rename so a crashing process never leaves a
/// partial file behind that the gateway worker would fail to parse.
///