Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Keep a verified recovery path through unattended update failures

pulse-triage[bot]329f2b00c40b
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 1778128b88..d521714848 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -6406,6 +6406,46 @@ covers the recorded snapshot and its removal. Local shell suites
`test-script-reference-integrity.sh`) pass; hosted Go installtest execution
remains required and is not claimed here.
+### Verified unattended-update backup and owned rollback
+
+`scripts/pulse-auto-update.sh` runs `perform_update` as a conditional, so Bash
+`errexit` is not a substitute for explicit snapshot and restore checks. Before
+executing the signed installer it must have a private unique rollback directory
+and successful, byte-compared copies of every existing regular binary at both
+supported install paths and the optional `VERSION` file. Missing binaries,
+symlinks/non-regular snapshot sources, allocation/copy/comparison failures and
+failed download/signature verification stop before installer mutation. An
+unneeded pre-mutation snapshot and verification files are removed on return.
+
+Installer failure, mismatched version and failure to restore a previously active
+service share one rollback path. It stops the service, stages and compares all
+saved files before any replacement, and renames each into its recorded original
+path without following a new symlink or treating a directory as a destination.
+Files absent before the attempt remain absent after recovery, including the
+legacy/current binary alternative and `VERSION`. Metadata is preserved. A
+partial restore must not invoke the RETURN restart backstop. The backup remains
+with a manual-recovery diagnostic if stop, staging, replacement, absence restore
+or prior-active service recovery fails. It is discarded only after complete
+recovery, or after the replacement version and required liveness are verified.
+Previously inactive services are not started by rollback. The RETURN trap still
+disarms itself and cannot leak locals into a later caller's return.
+
+This strengthens the existing binary/version recovery guarantee, not full
+configuration, database, power-loss or authenticated/native acceptance. Stable
+selection, Pro exclusion, signature identity/key/namespace, opt-in policy and
+the installer's own configuration backup remain unchanged.
+
+Verification: `scripts/installtests/pulse_auto_update_test.go`
+`TestAutoUpdateBackupTransaction` executes the complete updater under the real
+conditional caller with locally signed installers, real executable version reads
+and file operations, and bounded fake download/systemd boundaries. It covers
+snapshot admission, all three original failure paths, both binary layouts and
+absence, retained recovery failures, symlink/directory replacement, file modes,
+prior-active-only restoration, configuration/identity preservation and trap
+cleanup. Exact-parent negative controls must reject ignored snapshot failures
+and loss of the backup after a failed restore. Synthetic proof is not a deployed
+update, native systemd migration or reporter confirmation.
+
### Governed dependency floors for the go-minor-patch group
The managed `go-minor-patch` group advances three direct modules together with
diff --git a/scripts/installtests/pulse_auto_update_test.go b/scripts/installtests/pulse_auto_update_test.go
index 9b319190aa..90e045e699 100644
--- a/scripts/installtests/pulse_auto_update_test.go
+++ b/scripts/installtests/pulse_auto_update_test.go
@@ -610,3 +610,280 @@ echo "AFTER_CALLER"
t.Fatalf("perform_update leaked its RETURN trap; a later function return aborted under set -u:\n%s", got)
}
}
+
+// Exercise the complete sourced updater in its real conditional-call context.
+// Only downloads and systemd are replaced; file copies, comparisons, renames,
+// executable version reads and SSH signature verification are real and local.
+func TestAutoUpdateBackupTransaction(t *testing.T) {
+ if _, err := exec.LookPath("ssh-keygen"); err != nil {
+ t.Skip("ssh-keygen unavailable for signed offline installer fixture")
+ }
+ type scenario struct {
+ name, fault, outcome, layout string
+ noVersion, retained, success, preflight bool
+ }
+ cases := []scenario{
+ {name: "backup_directory_failure", fault: "backup_dir", preflight: true},
+ {name: "binary_snapshot_failure", fault: "backup_binary", preflight: true},
+ {name: "version_snapshot_failure", fault: "backup_version", preflight: true},
+ {name: "corrupt_snapshot", fault: "backup_corrupt", preflight: true},
+ {name: "installer_file_failure", fault: "installer_tmp", preflight: true},
+ {name: "signature_file_failure", fault: "signature_tmp", preflight: true},
+ {name: "missing_binary", fault: "no_binary", preflight: true},
+ {name: "symlink_binary", fault: "binary_symlink", preflight: true},
+ {name: "symlink_version", fault: "version_symlink", preflight: true},
+ {name: "installer_download_failure", fault: "download_installer", preflight: true},
+ {name: "signature_download_failure", fault: "download_signature", preflight: true},
+ {name: "invalid_signature", fault: "invalid_signature", preflight: true},
+ {name: "installer_failure", outcome: "failure"},
+ {name: "wrong_version", outcome: "mismatch"},
+ {name: "original_version_absent", outcome: "failure", noVersion: true},
+ {name: "legacy_layout_migration", outcome: "failure", layout: "legacy"},
+ {name: "both_binary_paths", outcome: "failure", layout: "both"},
+ {name: "new_destination_symlink", outcome: "symlink"},
+ {name: "rollback_stop_failure", fault: "stop", outcome: "failure", retained: true},
+ {name: "rollback_allocation_failure", fault: "restore_tmp", outcome: "failure", retained: true},
+ {name: "rollback_copy_failure", fault: "restore_copy", outcome: "failure", retained: true},
+ {name: "corrupt_rollback_copy", fault: "restore_corrupt", outcome: "failure", retained: true},
+ {name: "rollback_rename_failure", fault: "restore_rename", outcome: "failure", retained: true},
+ {name: "version_restore_failure", fault: "version_rename", outcome: "failure", retained: true},
+ {name: "new_destination_directory", outcome: "directory", retained: true},
+ {name: "successful_update", success: true},
+ }
+ t.Run("new_service_failure", func(t *testing.T) {
+ runAutoUpdateTransactionScenario(t, "", "service_failure", "", "true", false, false, false, false)
+ })
+ for _, tc := range cases {
+ for _, active := range []string{"true", "false"} {
+ t.Run(tc.name+"/prior_active_"+active, func(t *testing.T) {
+ runAutoUpdateTransactionScenario(t, tc.fault, tc.outcome, tc.layout, active, tc.noVersion, tc.preflight, tc.retained, tc.success)
+ })
+ }
+ }
+ t.Run("restored_service_start_failure", func(t *testing.T) {
+ runAutoUpdateTransactionScenario(t, "restart", "failure", "", "true", false, false, true, false)
+ })
+ t.Run("restored_service_liveness_failure", func(t *testing.T) {
+ runAutoUpdateTransactionScenario(t, "restart_liveness", "failure", "", "true", false, false, true, false)
+ })
+}
+
+func runAutoUpdateTransactionScenario(t *testing.T, fault, outcome, layout, active string, noVersion, preflight, retained, success bool) {
+ t.Helper()
+ updater, err := filepath.Abs(repoFile("scripts", "pulse-auto-update.sh"))
+ if err != nil {
+ t.Fatal(err)
+ }
+ dir := t.TempDir()
+ script := `
+set -euo pipefail
+source "$UPDATER_UNDER_TEST"
+INSTALL_DIR="$FIXTURE_DIR/install"
+CONFIG_DIR="$FIXTURE_DIR/config"
+mkdir -p "$INSTALL_DIR/bin" "$CONFIG_DIR" "$FIXTURE_DIR/tmp" "$FIXTURE_DIR/original"
+printf 'operator settings unchanged\n' > "$CONFIG_DIR/system.json"
+printf 'local identity unchanged\n' > "$CONFIG_DIR/agent-id"
+printf 'victim unchanged\n' > "$FIXTURE_DIR/victim"
+printf '#!/usr/bin/env bash\nprintf "Pulse v6.4.5\\n"\n' > "$FIXTURE_DIR/original/pulse-bin"
+printf '#!/usr/bin/env bash\nprintf "Pulse v6.4.4\\n"\n' > "$FIXTURE_DIR/original/pulse-legacy"
+printf 'v6.4.5\n' > "$FIXTURE_DIR/original/VERSION"
+chmod 751 "$FIXTURE_DIR/original/pulse-bin" "$FIXTURE_DIR/original/pulse-legacy"
+chmod 640 "$FIXTURE_DIR/original/VERSION"
+case "$LAYOUT" in
+ legacy) cp -p "$FIXTURE_DIR/original/pulse-bin" "$INSTALL_DIR/pulse" ;;
+ both) cp -p "$FIXTURE_DIR/original/pulse-bin" "$INSTALL_DIR/bin/pulse"; cp -p "$FIXTURE_DIR/original/pulse-legacy" "$INSTALL_DIR/pulse" ;;
+ *) cp -p "$FIXTURE_DIR/original/pulse-bin" "$INSTALL_DIR/bin/pulse" ;;
+esac
+if [[ "$NO_VERSION" == false ]]; then cp -p "$FIXTURE_DIR/original/VERSION" "$INSTALL_DIR/VERSION"; fi
+case "$FAULT" in
+ no_binary) rm -f "$INSTALL_DIR/bin/pulse" ;;
+ binary_symlink) mv "$INSTALL_DIR/bin/pulse" "$FIXTURE_DIR/original/linked-binary"; ln -s "$FIXTURE_DIR/original/linked-binary" "$INSTALL_DIR/bin/pulse" ;;
+ version_symlink) rm "$INSTALL_DIR/VERSION"; ln -s "$FIXTURE_DIR/original/VERSION" "$INSTALL_DIR/VERSION" ;;
+esac
+printf '%s\n' "$PRIOR_ACTIVE" > "$FIXTURE_DIR/active"
+export FIXTURE_DIR OUTCOME FAULT
+cat > "$FIXTURE_DIR/installer" <<'INSTALLER'
+set -euo pipefail
+printf 'executed\n' > "$FIXTURE_DIR/installer-executed"
+printf 'false\n' > "$FIXTURE_DIR/active"
+mkdir -p "$PULSE_INSTALL_DIR/bin"
+new_version=v6.5.0
+[[ "$OUTCOME" != mismatch ]] || new_version=v6.4.6
+printf '#!/usr/bin/env bash\nprintf "Pulse %s\\n"\n' "$new_version" > "$PULSE_INSTALL_DIR/bin/pulse"
+chmod 700 "$PULSE_INSTALL_DIR/bin/pulse"
+if [[ -f "$PULSE_INSTALL_DIR/pulse" ]]; then printf 'changed legacy binary\n' > "$PULSE_INSTALL_DIR/pulse"; fi
+printf '%s\n' "$new_version" > "$PULSE_INSTALL_DIR/VERSION"
+chmod 600 "$PULSE_INSTALL_DIR/VERSION"
+if [[ "$OUTCOME" == symlink ]]; then
+ rm "$PULSE_INSTALL_DIR/bin/pulse"
+ ln -s "$FIXTURE_DIR/victim" "$PULSE_INSTALL_DIR/bin/pulse"
+fi
+if [[ "$OUTCOME" == directory ]]; then
+ rm "$PULSE_INSTALL_DIR/bin/pulse"
+ mkdir "$PULSE_INSTALL_DIR/bin/pulse"
+ printf 'unexpected directory\n' > "$PULSE_INSTALL_DIR/bin/pulse/keep"
+fi
+case "$OUTCOME" in failure|symlink|directory) exit 23 ;; esac
+exit 0
+INSTALLER
+command ssh-keygen -q -t ed25519 -N '' -f "$FIXTURE_DIR/fixture-key"
+PINNED_RELEASE_SSH_PUBLIC_KEY=$(cat "$FIXTURE_DIR/fixture-key.pub")
+command ssh-keygen -Y sign -f "$FIXTURE_DIR/fixture-key" -n pulse-install "$FIXTURE_DIR/installer" >/dev/null 2>&1
+[[ "$FAULT" != invalid_signature ]] || printf 'tampered\n' >> "$FIXTURE_DIR/installer"
+log() { printf '[%s] %s\n' "$1" "${*:2}"; }
+detect_service_name() { printf 'pulse\n'; }
+sleep() { :; }
+# Keep real crypto but place all temporary files inside this disposable fixture.
+mktemp() {
+ local -a args=("$@")
+ local template="${args[${#args[@]}-1]}" result
+ case "$template:$FAULT" in
+ /tmp/pulse-backup.*:backup_dir|/tmp/pulse-update-installer.XXXXXX:installer_tmp|/tmp/pulse-update-installer.sig.*:signature_tmp|*.rollback.*:restore_tmp) return 1 ;;
+ esac
+ if [[ "$template" == /tmp/* ]]; then args[${#args[@]}-1]="$FIXTURE_DIR/tmp/${template##*/}"; fi
+ result=$(command mktemp "${args[@]}") || return
+ if [[ "$template" == /tmp/pulse-backup.* ]]; then printf '%s\n' "$result" > "$FIXTURE_DIR/backup-path"; fi
+ printf '%s\n' "$result"
+}
+# Record/clean the parent's timestamp backup as well, for the negative control.
+date() { printf 'transaction-%s\n' "${FIXTURE_DIR##*/}"; }
+mkdir() {
+ if [[ "${*: -1}" == /tmp/pulse-backup-* ]]; then printf '%s\n' "${*: -1}" > "$FIXTURE_DIR/backup-path"; fi
+ command mkdir "$@"
+}
+cp() {
+ local src="${@: -2:1}" dest="${@: -1}"
+ if [[ "$dest" == *pulse-backup* ]]; then
+ case "$FAULT:${src##*/}" in backup_binary:pulse|backup_version:VERSION) return 1 ;; esac
+ command cp "$@" || return
+ if [[ "$FAULT" == backup_corrupt ]]; then
+ [[ -d "$dest" ]] && dest="$dest/${src##*/}"
+ printf 'corrupt\n' > "$dest"
+ fi
+ elif [[ "$src" == *pulse-backup*/* ]]; then
+ [[ "$FAULT" != restore_copy ]] || return 1
+ command cp "$@" || return
+ [[ "$FAULT" != restore_corrupt ]] || printf 'corrupt\n' > "$dest"
+ else
+ command cp "$@"
+ fi
+}
+mv() {
+ local dest="${*: -1}"
+ if [[ "$FAULT" == restore_rename && "$dest" == "$INSTALL_DIR/bin/pulse" ]]; then return 1; fi
+ if [[ "$FAULT" == version_rename && "$dest" == "$INSTALL_DIR/VERSION" ]]; then return 1; fi
+ command mv "$@"
+}
+curl() {
+ local out="" url="" arg
+ while (( $# )); do
+ arg="$1"; shift
+ case "$arg" in -o) out="$1"; shift ;; https://*) url="$arg" ;; esac
+ done
+ printf '%s\n' "$url" >> "$FIXTURE_DIR/downloads"
+ if [[ "$url" == *.sshsig ]]; then
+ [[ "$FAULT" != download_signature ]] || return 1
+ command cp "$FIXTURE_DIR/installer.sshsig" "$out"
+ else
+ [[ "$FAULT" != download_installer ]] || return 1
+ command cp "$FIXTURE_DIR/installer" "$out"
+ fi
+}
+systemctl() {
+ case "$1" in
+ is-active) [[ "$(cat "$FIXTURE_DIR/active")" == true ]] ;;
+ stop)
+ printf 'stop\n' >> "$FIXTURE_DIR/service-operations"
+ [[ "$FAULT" != stop ]] || return 1
+ printf 'false\n' > "$FIXTURE_DIR/active"
+ ;;
+ start|restart)
+ printf '%s:%s\n' "$1" "$(get_current_version)" >> "$FIXTURE_DIR/service-operations"
+ [[ "$FAULT" != restart ]] || return 1
+ if [[ "$OUTCOME" == service_failure && "$(get_current_version)" != v6.4.5 ]]; then return 1; fi
+ [[ "$FAULT" == restart_liveness ]] || printf 'true\n' > "$FIXTURE_DIR/active"
+ ;;
+ *) return 1 ;;
+ esac
+}
+cleanup_fixture() {
+ if [[ -f "$FIXTURE_DIR/backup-path" ]]; then
+ local old_backup; old_backup=$(cat "$FIXTURE_DIR/backup-path")
+ case "$old_backup" in /tmp/pulse-backup-transaction-*) command rm -rf -- "$old_backup" ;; esac
+ fi
+}
+trap cleanup_fixture EXIT
+result=failure
+if perform_update v6.5.0; then result=success; fi
+[[ "$result" == "$EXPECTED_RESULT" ]] || { echo "unexpected result: $result"; exit 1; }
+[[ -z "$(trap -p RETURN)" ]] || { echo 'leaked RETURN trap'; exit 1; }
+caller() { :; }; caller
+[[ "$(cat "$CONFIG_DIR/system.json")" == 'operator settings unchanged' ]]
+[[ "$(cat "$CONFIG_DIR/agent-id")" == 'local identity unchanged' ]]
+[[ "$(cat "$FIXTURE_DIR/victim")" == 'victim unchanged' ]]
+if [[ "$PREFLIGHT" == true ]]; then
+ [[ ! -f "$FIXTURE_DIR/installer-executed" ]] || { echo 'installer executed without a usable backup/admission'; exit 1; }
+ [[ ! -s "$FIXTURE_DIR/service-operations" ]] || { echo 'service mutated on rejected preflight'; exit 1; }
+ [[ "$(cat "$FIXTURE_DIR/active")" == "$PRIOR_ACTIVE" ]]
+else
+ [[ -f "$FIXTURE_DIR/installer-executed" ]]
+fi
+backup=""; [[ ! -f "$FIXTURE_DIR/backup-path" ]] || backup=$(cat "$FIXTURE_DIR/backup-path")
+if [[ "$RETAINED" == true ]]; then
+ [[ -d "$backup" ]] || { echo 'rollback backup lost after failed recovery'; exit 1; }
+ [[ "$(stat -c '%a' "$backup")" == 700 ]]
+ cmp "$FIXTURE_DIR/original/pulse-bin" "$backup/pulse-bin"
+ cmp "$FIXTURE_DIR/original/VERSION" "$backup/VERSION"
+else
+ [[ -z "$backup" || ! -e "$backup" ]] || { echo 'unneeded backup leaked'; exit 1; }
+fi
+# Incomplete file restoration must not activate an unverified executable.
+case "$FAULT" in restore_tmp|restore_copy|restore_corrupt|restore_rename|version_rename|stop)
+ if [[ -f "$FIXTURE_DIR/service-operations" ]]; then
+ ! grep -Eq '^(start|restart):' "$FIXTURE_DIR/service-operations"
+ fi
+ ;;
+esac
+if [[ "$PREFLIGHT" != true && "$RETAINED" != true && "$EXPECTED_RESULT" != success ]]; then
+ case "$LAYOUT" in
+ legacy) [[ ! -e "$INSTALL_DIR/bin/pulse" ]]; cmp "$FIXTURE_DIR/original/pulse-bin" "$INSTALL_DIR/pulse" ;;
+ both) cmp "$FIXTURE_DIR/original/pulse-bin" "$INSTALL_DIR/bin/pulse"; cmp "$FIXTURE_DIR/original/pulse-legacy" "$INSTALL_DIR/pulse" ;;
+ *) cmp "$FIXTURE_DIR/original/pulse-bin" "$INSTALL_DIR/bin/pulse"; [[ ! -e "$INSTALL_DIR/pulse" ]] ;;
+ esac
+ if [[ "$NO_VERSION" == true ]]; then
+ [[ ! -e "$INSTALL_DIR/VERSION" ]]
+ else
+ cmp "$FIXTURE_DIR/original/VERSION" "$INSTALL_DIR/VERSION"
+ [[ "$(stat -c '%a' "$INSTALL_DIR/VERSION")" == 640 ]]
+ fi
+ [[ "$(get_current_version)" == v6.4.5 ]]
+ binary="$INSTALL_DIR/bin/pulse"; [[ "$LAYOUT" != legacy ]] || binary="$INSTALL_DIR/pulse"
+ [[ "$(stat -c '%a' "$binary")" == 751 ]]
+ [[ "$(cat "$FIXTURE_DIR/active")" == "$PRIOR_ACTIVE" ]]
+fi
+if [[ "$EXPECTED_RESULT" == success ]]; then [[ "$(get_current_version)" == v6.5.0 ]]; fi
+printf 'TRANSACTION_ASSERTIONS_PASSED\n'
+`
+ cmd := exec.Command("bash", "-c", script)
+ boolString := func(v bool) string {
+ if v {
+ return "true"
+ }
+ return "false"
+ }
+ want := "failure"
+ if success {
+ want = "success"
+ }
+ cmd.Env = append(os.Environ(), "UPDATER_UNDER_TEST="+updater, "FIXTURE_DIR="+dir,
+ "FAULT="+fault, "OUTCOME="+outcome, "LAYOUT="+layout, "PRIOR_ACTIVE="+active,
+ "NO_VERSION="+boolString(noVersion), "PREFLIGHT="+boolString(preflight),
+ "RETAINED="+boolString(retained), "EXPECTED_RESULT="+want)
+ out, err := cmd.CombinedOutput()
+ if err != nil {
+ t.Fatalf("complete updater transaction: %v\n%s", err, out)
+ }
+ if !strings.Contains(string(out), "TRANSACTION_ASSERTIONS_PASSED") {
+ t.Fatalf("transaction assertions did not finish:\n%s", out)
+ }
+}
diff --git a/scripts/pulse-auto-update.sh b/scripts/pulse-auto-update.sh
index d0526b0fb1..b965e9b42e 100755
--- a/scripts/pulse-auto-update.sh
+++ b/scripts/pulse-auto-update.sh
@@ -380,6 +380,14 @@ perform_update() {
local service_name=$(detect_service_name)
local installer_tmp=""
local signature_tmp=""
+ local backup_dir=""
+ local retain_backup="false"
+ local restart_allowed="true"
+ local -a file_paths=("$INSTALL_DIR/bin/pulse" "$INSTALL_DIR/pulse" "$INSTALL_DIR/VERSION")
+ local -a backup_names=(pulse-bin pulse-legacy VERSION)
+ local -a file_present=(false false false)
+ local -a restore_files=("" "" "")
+ local i
# Capture whether Pulse was running before the update so we can guarantee it
# comes back up afterwards (#1323: auto-update could leave it stopped on
@@ -395,7 +403,7 @@ perform_update() {
# trap is not scoped to the function that set it, so leaving it installed
# makes it re-run when any later function returns — with these locals gone
# that aborted the updater under set -u after a successful update (#2128).
- trap 'ensure_service_restarted "$service_name" "$service_was_active"; trap - RETURN' RETURN
+ trap 'trap - RETURN; rm -f -- "${installer_tmp:-}" "${signature_tmp:-}" "${restore_files[@]}"; if [[ -n "$backup_dir" && "$retain_backup" == "false" ]]; then rm -rf -- "$backup_dir"; fi; if [[ "$restart_allowed" == "true" ]]; then ensure_service_restarted "$service_name" "$service_was_active"; fi' RETURN
# Refuse to install a prerelease via the unattended updater. The stable
# channel must never cross onto a tag like v6.0.0-rc.2, even if every
@@ -407,22 +415,33 @@ perform_update() {
log info "Starting update to $new_version"
- # Create backup of current installation
- local backup_dir="/tmp/pulse-backup-$(date +%Y%m%d-%H%M%S)"
- log info "Creating backup in $backup_dir"
- mkdir -p "$backup_dir"
-
- # Backup binary
- if [[ -f "$INSTALL_DIR/bin/pulse" ]]; then
- cp -a "$INSTALL_DIR/bin/pulse" "$backup_dir/" || true
- elif [[ -f "$INSTALL_DIR/pulse" ]]; then
- cp -a "$INSTALL_DIR/pulse" "$backup_dir/" || true
+ # main calls this function in an if condition, which disables errexit
+ # throughout it. Check every prerequisite explicitly before the installer
+ # can mutate anything. A private, unique directory also avoids collisions
+ # with another attempt or a pre-created path in the shared /tmp directory.
+ if [[ ! -f "${file_paths[0]}" && ! -f "${file_paths[1]}" ]]; then
+ log error "No installed Pulse binary to back up; refusing update"
+ return 1
fi
-
- # Backup VERSION file
- if [[ -f "$INSTALL_DIR/VERSION" ]]; then
- cp -a "$INSTALL_DIR/VERSION" "$backup_dir/" || true
+ if ! backup_dir=$(mktemp -d /tmp/pulse-backup.XXXXXX); then
+ log error "Could not create rollback backup; refusing update"
+ return 1
fi
+ log info "Creating backup in $backup_dir"
+ for i in "${!file_paths[@]}"; do
+ if [[ -e "${file_paths[i]}" || -L "${file_paths[i]}" ]]; then
+ if [[ ! -f "${file_paths[i]}" || -L "${file_paths[i]}" ]]; then
+ log error "Unsupported rollback source ${file_paths[i]}; refusing update"
+ return 1
+ fi
+ if ! cp -p -- "${file_paths[i]}" "$backup_dir/${backup_names[i]}" ||
+ ! cmp -s -- "${file_paths[i]}" "$backup_dir/${backup_names[i]}"; then
+ log error "Could not verify rollback backup for ${file_paths[i]}; refusing update"
+ return 1
+ fi
+ file_present[i]=true
+ fi
+ done
# Download update using install script (safest method)
log info "Downloading and installing update"
@@ -441,9 +460,11 @@ perform_update() {
fi
fi
- installer_tmp=$(mktemp /tmp/pulse-update-installer.XXXXXX)
- signature_tmp=$(mktemp /tmp/pulse-update-installer.sig.XXXXXX)
- trap 'rm -f "${installer_tmp:-}" "${signature_tmp:-}"; ensure_service_restarted "$service_name" "$service_was_active"; trap - RETURN' RETURN
+ if ! installer_tmp=$(mktemp /tmp/pulse-update-installer.XXXXXX) ||
+ ! signature_tmp=$(mktemp /tmp/pulse-update-installer.sig.XXXXXX); then
+ log error "Could not create installer verification files; refusing update"
+ return 1
+ fi
if ! curl -fsSL "$install_script_url" -o "$installer_tmp"; then
log error "Failed to download installer from $install_script_url"
@@ -458,6 +479,7 @@ perform_update() {
fi
log info "Installer signature verified"
+ local update_accepted="false"
if env \
"PULSE_SERVICE_NAME=$service_name" \
"PULSE_INSTALL_DIR=$INSTALL_DIR" \
@@ -467,10 +489,11 @@ perform_update() {
log info "installer: $line"
done; then
- log info "Update successfully installed"
+ log info "Installer completed; verifying update"
# Verify new version
- local installed_version=$(get_current_version)
+ local installed_version
+ installed_version=$(get_current_version)
if [[ "$installed_version" == "$new_version" ]]; then
log info "Version verified: $installed_version"
@@ -485,82 +508,69 @@ perform_update() {
if ! wait_for_service_active "$service_name" 20; then
log error "Pulse service did not come back up after update"
-
- log info "Restoring from backup"
- if [[ -f "$backup_dir/pulse" ]]; then
- if [[ -f "$INSTALL_DIR/bin/pulse" ]]; then
- cp -f "$backup_dir/pulse" "$INSTALL_DIR/bin/pulse"
- else
- cp -f "$backup_dir/pulse" "$INSTALL_DIR/pulse"
- fi
- fi
- if [[ -f "$backup_dir/VERSION" ]]; then
- cp -f "$backup_dir/VERSION" "$INSTALL_DIR/VERSION"
- fi
-
- systemctl restart "$service_name" || true
- rm -rf "$backup_dir"
- return 1
+ else
+ update_accepted="true"
fi
+ else
+ update_accepted="true"
fi
-
- # Clean up backup
- rm -rf "$backup_dir"
-
- return 0
else
log error "Version mismatch after update. Expected: $new_version, Got: $installed_version"
-
- # Restore from backup
- log info "Restoring from backup"
- if [[ -f "$backup_dir/pulse" ]]; then
- if [[ -f "$INSTALL_DIR/bin/pulse" ]]; then
- cp -f "$backup_dir/pulse" "$INSTALL_DIR/bin/pulse"
- else
- cp -f "$backup_dir/pulse" "$INSTALL_DIR/pulse"
- fi
- fi
- if [[ -f "$backup_dir/VERSION" ]]; then
- cp -f "$backup_dir/VERSION" "$INSTALL_DIR/VERSION"
- fi
-
- # Restart service with old version
- systemctl restart "$service_name" || true
-
- # Clean up backup
- rm -rf "$backup_dir"
-
- return 1
fi
else
log error "Update installation failed"
-
- # Restore from backup
- log info "Restoring from backup"
- if [[ -f "$backup_dir/pulse" ]]; then
- if [[ -f "$INSTALL_DIR/bin/pulse" ]]; then
- cp -f "$backup_dir/pulse" "$INSTALL_DIR/bin/pulse"
- else
- cp -f "$backup_dir/pulse" "$INSTALL_DIR/pulse"
+ fi
+
+ if [[ "$update_accepted" == "true" ]]; then
+ log info "Update successfully installed and verified"
+ return 0
+ fi
+
+ # One rollback path for installer, version and liveness failures. Keep the
+ # backup and suppress the RETURN-trap restart until every file is restored;
+ # starting a partially restored executable would hide the recovery failure.
+ retain_backup="true"
+ restart_allowed="false"
+ log info "Restoring from backup"
+ if ! systemctl stop "$service_name"; then
+ log error "Could not stop Pulse for rollback; backup retained at $backup_dir; manual recovery required"
+ return 1
+ fi
+
+ # Stage and compare all saved files before replacing any destination. Each
+ # replacement is a same-directory rename, not a truncating copy into a
+ # running executable or a symlink created by the failed installer.
+ for i in "${!file_paths[@]}"; do
+ if [[ "${file_present[i]}" == "true" ]]; then
+ if ! restore_files[i]=$(mktemp "${file_paths[i]}.rollback.XXXXXX") ||
+ ! cp -p -- "$backup_dir/${backup_names[i]}" "${restore_files[i]}" ||
+ ! cmp -s -- "$backup_dir/${backup_names[i]}" "${restore_files[i]}"; then
+ log error "Could not stage rollback for ${file_paths[i]}; backup retained at $backup_dir; manual recovery required"
+ return 1
fi
fi
- if [[ -f "$backup_dir/VERSION" ]]; then
- cp -f "$backup_dir/VERSION" "$INSTALL_DIR/VERSION"
+ done
+ for i in "${!file_paths[@]}"; do
+ if [[ "${file_present[i]}" == "true" ]]; then
+ if ! mv -fT -- "${restore_files[i]}" "${file_paths[i]}"; then
+ log error "Could not restore ${file_paths[i]}; backup retained at $backup_dir; manual recovery required"
+ return 1
+ fi
+ elif ! rm -f -- "${file_paths[i]}"; then
+ log error "Could not restore absence of ${file_paths[i]}; backup retained at $backup_dir; manual recovery required"
+ return 1
fi
+ done
- # Restart the restored binary if Pulse was running before the update.
- # The installer stops the service before it can fail, so skipping this
- # left Pulse down indefinitely (#1630); the RETURN trap above is the
- # backstop if this path ever changes.
- if [[ "$service_was_active" == "true" ]]; then
- systemctl restart "$service_name" || true
+ if [[ "$service_was_active" == "true" ]]; then
+ if ! systemctl start "$service_name" || ! wait_for_service_active "$service_name" 20; then
+ log error "Restored Pulse could not be started; backup retained at $backup_dir; manual recovery required"
+ return 1
fi
-
- # Clean up backup
- rm -rf "$backup_dir"
-
- return 1
fi
+ retain_backup="false"
+ log info "Previous installation restored"
+ return 1
}
# Main update check