khive_runtime/daemon/supervisor_marker.rs
1//! Where the supervisor launcher's marker file lives.
2#![cfg(unix)]
3use std::path::PathBuf;
4
5use super::{default_socket_path, khive_dir, socket_path};
6
7/// Marker file the supervisor's launcher publishes before it execs `khived`.
8/// It records the job label, launcher/daemon PID, restart interval in seconds,
9/// and the launcher's incarnation claim. The launcher or deliberate-stop procedure
10/// removes its own claim; the daemon never writes or removes it. A client
11/// waits up to three restart intervals before a logged degraded bootstrap,
12/// bounded by its caller deadline, rather than racing normal supervisor
13/// startup. Reading and acting on this file is the client's decision
14/// (`khive-mcp`); this module
15/// only resolves where it lives. The default socket keeps `khived.supervisor`;
16/// a private socket appends `.supervisor-marker` to its complete pathname.
17///
18/// Overridable via the `KHIVE_SUPERVISOR_MARKER` env var (for tests).
19pub fn supervisor_marker_path() -> PathBuf {
20 if let Ok(p) = std::env::var("KHIVE_SUPERVISOR_MARKER") {
21 if !p.is_empty() {
22 return PathBuf::from(p);
23 }
24 }
25 let socket = socket_path();
26 if socket.as_os_str() == default_socket_path().as_os_str() {
27 khive_dir().join("khived.supervisor")
28 } else {
29 let mut marker = socket.into_os_string();
30 marker.push(".supervisor-marker");
31 PathBuf::from(marker)
32 }
33}