Derive a stable replica identity for lease ownership. Kubernetes sets `HOSTNAME` to the pod name, Docker sets it to the container ID, and systemd units inherit the machine hostname. `OPENSHELL_REPLICA_ID` allows explicit override. The UUID fallback handles edge cases where neither env var is set.
()
| 244 | /// `OPENSHELL_REPLICA_ID` allows explicit override. The UUID fallback |
| 245 | /// handles edge cases where neither env var is set. |
| 246 | pub fn replica_id() -> String { |
| 247 | std::env::var("OPENSHELL_REPLICA_ID") |
| 248 | .or_else(|_| std::env::var("HOSTNAME")) |
| 249 | .unwrap_or_else(|_| uuid::Uuid::new_v4().to_string()) |
| 250 | } |
| 251 | |
| 252 | #[cfg(test)] |
| 253 | mod tests { |
no outgoing calls
no test coverage detected