Рефакторинг под прод: nsenter-first транспорт, drift-aware reconcile, hardening daemon/lock/reboot/swap, расширенный status и build-скрипт

This commit is contained in:
2026-05-09 22:03:30 +05:00
parent d937f816bf
commit e7818054e8
16 changed files with 900 additions and 96 deletions
+17 -1
View File
@@ -11,7 +11,12 @@ impl FileLock {
fs::create_dir_all(parent)?;
}
if p.exists() {
anyhow::bail!("lock already exists: {path}");
let stale = is_stale_lock(p)?;
if stale {
let _ = fs::remove_file(p);
} else {
anyhow::bail!("lock already exists: {path}");
}
}
fs::write(p, std::process::id().to_string())?;
Ok(Self {
@@ -26,3 +31,14 @@ impl Drop for FileLock {
}
}
fn is_stale_lock(path: &Path) -> anyhow::Result<bool> {
let pid_raw = fs::read_to_string(path)?;
let pid = match pid_raw.trim().parse::<u32>() {
Ok(v) => v,
Err(_) => return Ok(true),
};
let proc_path = format!("/proc/{pid}");
Ok(!Path::new(&proc_path).exists())
}