Fixed exec bug

This commit is contained in:
Timmy
2026-07-15 14:55:27 +01:00
parent 549e0349d7
commit 2a7db16a77
3 changed files with 40 additions and 60 deletions
+6 -22
View File
@@ -60,9 +60,12 @@ pub async fn fetch_and_replace_binary(source_url: &str, target_path: &Path) -> R
// ── Full server upgrade (called from the running process) ─────────────────
/// Fetch a new binary, atomically replace the current executable, drain CRDT
/// persistence, and re-exec the running server process with its original args.
/// persistence, and exit so Docker restarts the container with the new binary.
///
/// The entrypoint script checks for a rebuilt binary at
/// /app/target/release/huskies and prefers it over the image-baked
/// /usr/local/bin/huskies.
///
/// This function never returns on success — `exec()` replaces the process.
/// On failure it returns `Err(message)` so the caller can report the error
/// while keeping the original server running.
pub async fn upgrade_and_reexec(source_url: &str, project_root: &Path) -> Result<String, String> {
@@ -70,26 +73,7 @@ pub async fn upgrade_and_reexec(source_url: &str, project_root: &Path) -> Result
fetch_and_replace_binary(source_url, &target).await?;
// Drain queued CRDT ops so nothing is lost when exec() replaces the process.
crate::crdt_state::flush_persistence(std::time::Duration::from_secs(5)).await;
// Clean up the port file so the new process can write a fresh one.
let port_file = project_root.join(".huskies_port");
if port_file.exists() {
let _ = std::fs::remove_file(&port_file);
}
let args: Vec<String> = std::env::args().collect();
slog!("[upgrade] Re-execing with new binary: {}", target.display());
use std::os::unix::process::CommandExt;
let err = std::process::Command::new(&target).args(&args[1..]).exec();
// exec() only returns on failure.
Err(format!(
"Failed to exec new binary at {}: {err}",
target.display()
))
crate::rebuild::drain_and_exit(project_root, "upgrade").await
}
// ── CLI upgrade (no re-exec) ─────────────────────────────────────────────