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.

fix(install): bound every wrapper kill and stop supervisors first

rcourtmandaf2ad7ff942
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 3c8fc65ab3..4915725589 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -92,7 +92,13 @@ surviving supervisors race to own one agent id, which presents as an agent that
restarts on its own or reverts to superseded arguments rather than as an
install failure. The supervisor match is subject to the same boundary rule as
the binary match, so stopping one agent's supervisor never stops a co-installed
-agent's.
+agent's. Removing an agent inherits the same ordering: a supervisor left
+looping while its agent is torn down restarts the agent that was just stopped,
+so uninstall stops the supervisor first as well. Because removal must also
+reach a supervisor that a superseded install left behind, its match may be
+looser about location than an install's, but never about the far end of the
+name: a backup copy of a wrapper script, or an editor holding one open, is not
+a supervisor and must never be a termination target.
Mock mode is a clean room on the report-admission boundary. Mock mode already
suspends pull-based PVE/PBS/PMG collection by never building those clients, and
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 69696a3101..8f73451a89 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -386,6 +386,13 @@ upgrade, update, release, or artifact-selection behavior.
second wrapper leaves two loops contending for one agent id with no install
error to show for it. NAS install paths must be symmetric on this point:
every branch that writes and launches a wrapper owes the same teardown.
+ Uninstall and teardown carry the same ordering obligation for the same
+ reason: a wrapper left looping while its agent is removed simply restarts
+ the agent that was just stopped. Teardown may match wrappers more broadly
+ than install, because it must also reach a wrapper invoked by a relative
+ path or stranded at a superseded location, but it stays bound at the far end
+ so a backup copy of a wrapper, or an editor holding one open, is never a
+ termination target.
FreeBSD-family uninstall must stop the rc.d daemon(8) supervisor before
removing the binary, then remove service registration, rc.conf enablement,
boot wrappers, PID files, token/state, and residual processes before it can
diff --git a/scripts/install.sh b/scripts/install.sh
index a38fd01ebd..7fad81cef7 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -3201,13 +3201,17 @@ if [[ "$UNINSTALL" == "true" ]]; then
fi
fi
- # Kill any running agent processes first.
+ # Kill wrapper scripts first: they are watchdogs, so stopping the agent
+ # while its wrapper still loops only races the respawn. No leading path
+ # separator here, unlike the install paths, so a wrapper invoked by a
+ # relative path or left at an older location is still caught. The dot is
+ # escaped and the far end bounded so an editor session or a .bak copy of
+ # the wrapper is not swept up with it.
+ pkill -f "start-pulse-agent\.sh([[:space:]]|$)" 2>/dev/null || true
+ # Then the agent itself.
# Use -x (exact process name match) to avoid killing THIS uninstall script,
# whose command line path contains "pulse-agent" (e.g. /boot/config/plugins/pulse-agent/install.sh).
pkill -x "pulse-agent" 2>/dev/null || true
- # Kill Unraid wrapper scripts — both current (start-pulse-agent.sh) and
- # legacy naming conventions.
- pkill -f "start-pulse-agent.sh" 2>/dev/null || true
sleep 1
# Systemd - unified agent
@@ -3248,9 +3252,11 @@ if [[ "$UNINSTALL" == "true" ]]; then
# Unraid
if [[ -f /etc/unraid-version ]] || [[ -d /boot/config/plugins/pulse-agent ]]; then
log_info "Removing Unraid installation..."
- # Stop running agents and their wrapper scripts.
+ # Stop the wrapper watchdogs before the agents they supervise, and keep
+ # the match bounded so a .bak copy or an editor session on the wrapper
+ # is not swept up.
+ pkill -f "start-pulse-agent\.sh([[:space:]]|$)" 2>/dev/null || true
pkill -x "pulse-agent" 2>/dev/null || true
- pkill -f "start-pulse-agent.sh" 2>/dev/null || true
sleep 1
# Remove from /boot/config/go - all pulse-related entries
@@ -3943,8 +3949,12 @@ if [[ -f /sbin/getcfg ]] || [[ -f /etc/config/qpkg.conf ]]; then
build_exec_args
log_info "Stopping any existing pulse agents..."
+ # Supervisor before the agent it supervises: the wrapper is a watchdog, so
+ # stopping the agent first only races the respawn. The dot is escaped and
+ # the far end bounded so an editor session or a .bak copy of the wrapper is
+ # not swept up with it.
+ pkill -f "/start-pulse-agent\.sh([[:space:]]|$)" 2>/dev/null || true
pkill -x "pulse-agent" 2>/dev/null || true
- pkill -f "start-pulse-agent.sh" 2>/dev/null || true
sleep 2
write_qnap_wrapper_script "$WRAPPER_SCRIPT" "$RUNTIME_BINARY" "$QNAP_STORED_BINARY" "$QNAP_LOG_DIR" "$STATE_DIR"
diff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.go
index 3330750b0a..3f1018f5e0 100644
--- a/scripts/installtests/install_sh_test.go
+++ b/scripts/installtests/install_sh_test.go
@@ -5222,3 +5222,69 @@ func TestInstallSHWatchdogKillPatternSparesSiblingWrapper(t *testing.T) {
t.Fatal("premise check failed: the loose pattern is supposed to match the target")
}
}
+
+// TestInstallSHWrapperKillsAreBoundedEverywhere pins every wrapper kill in the
+// installer, not just the Unraid install branch. A bare "start-pulse-agent.sh"
+// pattern leaves the dot as a wildcard and the far end unbounded, so it also
+// matches a .bak copy of the wrapper or an editor session holding it open.
+func TestInstallSHWrapperKillsAreBoundedEverywhere(t *testing.T) {
+ content, err := os.ReadFile(repoFile("scripts", "install.sh"))
+ if err != nil {
+ t.Fatalf("read install.sh: %v", err)
+ }
+ script := string(content)
+
+ if strings.Contains(script, `pkill -f "start-pulse-agent.sh"`) {
+ t.Error(`bare pkill -f "start-pulse-agent.sh" leaves the dot as a wildcard and the tail unbounded`)
+ }
+
+ wrapperKill := regexp.MustCompile(`pkill -f "[^"\n]*start-pulse-agent[^"\n]*"`)
+ found := wrapperKill.FindAllString(script, -1)
+ if len(found) == 0 {
+ t.Fatal("expected the installer to stop wrapper supervisors somewhere")
+ }
+ for _, match := range found {
+ if !strings.Contains(match, `\.sh`) {
+ t.Errorf("wrapper kill must escape the dot: %s", match)
+ }
+ if !strings.Contains(match, "[[:space:]]") {
+ t.Errorf("wrapper kill must bound its far end: %s", match)
+ }
+ }
+}
+
+// TestInstallSHStopsWrapperBeforeAgentInEveryBranch pins the ordering rule the
+// agent-lifecycle and deployment-installability contracts now carry: a wrapper
+// is a watchdog, so stopping the agent while its wrapper still loops merely
+// races the respawn. Every branch that stops both must stop the wrapper first.
+func TestInstallSHStopsWrapperBeforeAgentInEveryBranch(t *testing.T) {
+ content, err := os.ReadFile(repoFile("scripts", "install.sh"))
+ if err != nil {
+ t.Fatalf("read install.sh: %v", err)
+ }
+ lines := strings.Split(string(content), "\n")
+
+ // Walk the file and, for each wrapper kill, confirm the nearest agent kill
+ // that shares its stop block does not precede it.
+ for i, line := range lines {
+ if !strings.Contains(line, "pkill") || !strings.Contains(line, "start-pulse-agent") {
+ continue
+ }
+ // Look back a short window for an agent kill in the same block.
+ for back := i - 1; back >= 0 && back > i-12; back-- {
+ prev := lines[back]
+ if !strings.Contains(prev, "pkill") {
+ continue
+ }
+ if strings.Contains(prev, "start-pulse-agent") {
+ break
+ }
+ if strings.Contains(prev, `-x "pulse-agent"`) || strings.Contains(prev, "${RUNTIME_BINARY}") ||
+ strings.Contains(prev, "${BINARY_NAME}") || strings.Contains(prev, "${INSTALL_DIR}") {
+ t.Errorf("line %d stops the agent before its wrapper at line %d; the watchdog will respawn it:\n %s\n %s",
+ back+1, i+1, strings.TrimSpace(prev), strings.TrimSpace(line))
+ }
+ break
+ }
+ }
+}