From 1e648800ade52c280f48d74f0a68959a95906035 Mon Sep 17 00:00:00 2001 From: Dorian Date: Mon, 20 Apr 2026 13:04:09 -0400 Subject: [PATCH] =?UTF-8?q?release(v1.7.8-alpha):=20fix=20apply=20ETXTBSY?= =?UTF-8?q?=20=E2=80=94=20use=20mv=20instead=20of=20install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apply_update's binary swap called `sudo install -m 0755 src /usr/local/bin/archipelago`. install opens the destination for write with O_TRUNC; the kernel returns ETXTBSY (exit 1) when the path is a currently-running executable, which it always is during apply because apply_update is called by the archipelago RPC handler — running as archipelago itself. Every previous "Failed to apply update" was this one root cause; the manual sideload path only worked because we stopped the service first. rename() doesn't modify the file it replaces — it repoints the path at a new inode while the old inode stays alive for any process that has it mapped. `mv` uses rename(). Switched to `sudo mv` (with prior chmod+chown on the staging file) so the swap is atomic and tolerant of the running binary. Frontend tarball byte-identical to v1.7.7-alpha; only the binary version string changes. Artefacts: archipelago 2753daec…48094d 40377648 archipelago-frontend-1.7.8-alpha.tar.gz 4fb79664…0172e9 76984615 (reused) Co-Authored-By: Claude Opus 4.7 (1M context) --- core/Cargo.lock | 2 +- core/archipelago/Cargo.toml | 2 +- core/archipelago/src/update.rs | 36 +++++++++++++++++++--------------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/core/Cargo.lock b/core/Cargo.lock index 46f9083c..54e1d6ce 100644 --- a/core/Cargo.lock +++ b/core/Cargo.lock @@ -80,7 +80,7 @@ checksum = "a23eb6b1614318a8071c9b2521f36b424b2c83db5eb3a0fead4a6c0809af6e61" [[package]] name = "archipelago" -version = "1.7.7-alpha" +version = "1.7.8-alpha" dependencies = [ "anyhow", "archipelago-container", diff --git a/core/archipelago/Cargo.toml b/core/archipelago/Cargo.toml index 7229be2e..95befc3e 100644 --- a/core/archipelago/Cargo.toml +++ b/core/archipelago/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "archipelago" -version = "1.7.7-alpha" +version = "1.7.8-alpha" edition = "2021" description = "Archipelago Bitcoin Node OS - Native backend" authors = ["Archipelago Team"] diff --git a/core/archipelago/src/update.rs b/core/archipelago/src/update.rs index 3cef79a0..bc5e0af2 100644 --- a/core/archipelago/src/update.rs +++ b/core/archipelago/src/update.rs @@ -277,27 +277,31 @@ pub async fn apply_update(data_dir: &Path) -> Result<()> { match name.as_str() { "archipelago" => { - // /usr/local/bin is root-owned; archipelago user can't - // fs::copy into it directly. Use sudo install which handles - // the copy, mode, and ownership atomically. + // We're running FROM /usr/local/bin/archipelago right now, + // so we can't rewrite it in place — `install` / `cp` would + // hit ETXTBSY on the busy executable. Use `mv` instead: + // rename() is atomic and doesn't modify the existing file, + // it just re-points the path at a new inode. The currently + // running process keeps executing off the old inode; new + // invocations (i.e. after the post-apply systemctl + // restart) pick up the new binary. + let staged = src.to_string_lossy().to_string(); + let _ = tokio::process::Command::new("sudo") + .args(["chmod", "0755", &staged]) + .status() + .await; + let _ = tokio::process::Command::new("sudo") + .args(["chown", "root:root", &staged]) + .status() + .await; let status = tokio::process::Command::new("sudo") - .args([ - "install", - "-m", - "0755", - "-o", - "root", - "-g", - "root", - &src.to_string_lossy(), - "/usr/local/bin/archipelago", - ]) + .args(["mv", &staged, "/usr/local/bin/archipelago"]) .status() .await - .with_context(|| format!("Failed to spawn install for {}", name))?; + .with_context(|| format!("Failed to spawn mv for {}", name))?; if !status.success() { anyhow::bail!( - "sudo install failed for {} (exit {:?})", + "sudo mv failed for {} (exit {:?})", name, status.code() );