Add self-contained automated server upgrade package

This commit is contained in:
admin committed 2026-09-10 14:23:31 +02:00
1 parent 4d58fc7b66
commit 8e6c9a058f
14 files changed
+908 -26

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# The upgrade coordinator holds FD 9 for the complete install/check/backup cycle.
# Child tools may reuse that SAME open file description, never bypass the lock.
acquire_backup_lock() {
[[ $LOCKFILE == /* && ! -L $LOCKFILE ]] || { echo 'Unsafe lock path' >&2; return 1; }
if [[ -e $LOCKFILE ]]; then
[[ -f $LOCKFILE && ! -s $LOCKFILE && $(stat -c %u "$LOCKFILE") == 0 ]] || { echo 'Unsafe existing lock file' >&2; return 1; }
fi
if [[ ${APP_BACKUP_INHERIT_LOCK:-0} == 1 ]]; then
[[ -e /proc/self/fd/9 && $(stat -Lc '%d:%i' /proc/self/fd/9) == "$(stat -Lc '%d:%i' "$LOCKFILE")" ]] || {
echo 'Inherited lock descriptor does not match configured lock' >&2; return 1;
}
else
exec 9>"$LOCKFILE"
fi
flock -n 9 || { echo "Another backup/restore/update holds $LOCKFILE" >&2; return 1; }
}