fix(forgejo): install the pinned release by renaming over the running binary (#136)

setup.sh downloaded straight to /usr/local/bin/forgejo while forgejo.service
was running, which fails with ETXTBSY ("Text file busy"). Every deploy logged
"forgejo download failed" and prod stayed on 11.0.1 although the pin is
11.0.15. Download to forgejo.new, check its --version, and rename it over the
old binary; the existing `systemctl restart forgejo` then starts the new one.
A failed or wrong download now keeps the installed binary instead of warning
that the backend will be unavailable.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Anthony Ettinger 2026-10-01 03:32:02 -07:00 • committed by GitHub
parent 2537977711
commit f5c8e31d26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1104,9 +1104,21 @@ if [ "$FORGEJO" = "1" ]; then
esac esac
if [ -n "$FJ_ARCH" ]; then if [ -n "$FJ_ARCH" ]; then
log "downloading forgejo ${FORGEJO_VERSION} (${FJ_ARCH})" log "downloading forgejo ${FORGEJO_VERSION} (${FJ_ARCH})"
curl -fsSL "https://codeberg.org/forgejo/forgejo/releases/download/v${FORGEJO_VERSION}/forgejo-${FORGEJO_VERSION}-linux-${FJ_ARCH}" \ # Download beside the binary and rename over it. Writing straight to
-o /usr/local/bin/forgejo && chmod 0755 /usr/local/bin/forgejo \ # /usr/local/bin/forgejo while forgejo.service runs fails with ETXTBSY
|| warn "forgejo download failed — backend will be unavailable" # ("Text file busy"), which left prod pinned to an old release with a
# "download failed" warning on every redeploy. A rename is atomic and
# legal on a running executable; the old inode lives until the restart.
if curl -fsSL "https://codeberg.org/forgejo/forgejo/releases/download/v${FORGEJO_VERSION}/forgejo-${FORGEJO_VERSION}-linux-${FJ_ARCH}" \
-o /usr/local/bin/forgejo.new \
&& chmod 0755 /usr/local/bin/forgejo.new \
&& /usr/local/bin/forgejo.new --version 2>/dev/null | grep -q "$FORGEJO_VERSION"; then
mv -f /usr/local/bin/forgejo.new /usr/local/bin/forgejo
log "forgejo ${FORGEJO_VERSION} installed"
else
rm -f /usr/local/bin/forgejo.new
warn "forgejo ${FORGEJO_VERSION} download failed — keeping the installed binary"
fi
fi fi
fi fi