deploy: atomic binary replace (fix "Text file busy")
Build (Dev) / build (push) Successful in 10s
CI / quality (push) Successful in 10s
CI / quality (pull_request) Successful in 10s

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 <noreply@anthropic.com>
This commit is contained in:
Joshua King
2026-06-05 11:57:15 -04:00
parent c6d812cca2
commit 9fc80a27c9
+9 -4
View File
@@ -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