Рефакторинг под прод: nsenter-first транспорт, drift-aware reconcile, hardening daemon/lock/reboot/swap, расширенный status и build-скрипт
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user