From 9fc80a27c9ef2ec703b2eff25601245b689995ed Mon Sep 17 00:00:00 2001 From: Joshua King Date: Fri, 5 Jun 2026 11:57:15 -0400 Subject: [PATCH] deploy: atomic binary replace (fix "Text file busy") cp over /opt/remoterig/remoterig fails with "Text file busy" once the service is running. Copy to a .new file and rename over the target (works on a live binary), in both the deploy and rollback paths. Co-Authored-By: Claude Opus 4.8 --- scripts/deploy.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/scripts/deploy.sh b/scripts/deploy.sh index b458d06..381848b 100755 --- a/scripts/deploy.sh +++ b/scripts/deploy.sh @@ -72,8 +72,12 @@ fi # 2. Deploy new binary # --------------------------------------------------------------------------- info "Deploying new binary..." -cp "${BINARY}" "${DEPLOY_PATH}" -chmod +x "${DEPLOY_PATH}" +# Atomic replace: copy alongside then rename over the target. A plain +# cp over a running executable fails with "Text file busy"; rename swaps +# the directory entry and works while the old binary is still running. +cp "${BINARY}" "${DEPLOY_PATH}.new" +chmod +x "${DEPLOY_PATH}.new" +mv -f "${DEPLOY_PATH}.new" "${DEPLOY_PATH}" ok "Binary installed at ${DEPLOY_PATH}" # --------------------------------------------------------------------------- @@ -116,8 +120,9 @@ else # ----------------------------------------------------------------------- if [ -f "${BACKUP}" ]; then info "Restoring backup: ${BACKUP}" - cp "${BACKUP}" "${DEPLOY_PATH}" - chmod +x "${DEPLOY_PATH}" + cp "${BACKUP}" "${DEPLOY_PATH}.new" + chmod +x "${DEPLOY_PATH}.new" + mv -f "${DEPLOY_PATH}.new" "${DEPLOY_PATH}" systemctl restart "${SERVICE}" 2>/dev/null || true