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): stop the previous watchdog before starting a new one on Unraid

rcourtmand7d6753d0572
diff --git a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
index 99031ad609..3c8fc65ab3 100644
--- a/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
+++ b/docs/release-control/v6/internal/subsystems/agent-lifecycle.md
@@ -84,6 +84,16 @@ well as the installer, and most sharply there, because restarting through the
wrapper is the documented runbook step and would otherwise repeat the
collateral kill on every use.
+Exactly one supervisor may own an agent at a time. An install that starts a
+watchdog must first stop any watchdog already supervising that same agent, and
+must stop it before stopping the agent itself, because a watchdog left running
+respawns the agent mid-install with the previous binary and arguments. Two
+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.
+
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
push-based agent reports are held to the same rule: `ApplyHostReport`,
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.md
index 3abc526e74..69696a3101 100644
--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md
+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md
@@ -379,6 +379,13 @@ upgrade, update, release, or artifact-selection behavior.
patterns must therefore terminate at a whitespace-or-end boundary, and a
deliberately path-agnostic sweep must match the process name exactly rather
than a bare command-line substring.
+ Platforms whose agent runs under a generated watchdog wrapper rather than an
+ init system must also stop the previous wrapper before starting a new one,
+ and must stop it before the agent it supervises. Killing a supervised agent
+ while its wrapper still loops merely races the respawn, and appending a
+ 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.
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 6f90ea8bbb..a38fd01ebd 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -3796,6 +3796,15 @@ if [[ -f /etc/unraid-version ]]; then
# Kill any existing pulse agents.
log_info "Stopping any existing pulse agents..."
+ # Stop the supervisor before the agent it supervises. The wrapper is a
+ # watchdog loop, so killing the agent while its wrapper is still running
+ # only races the respawn, and leaving that wrapper alive alongside the one
+ # started at the end of this install leaves two loops competing to own the
+ # same agent id. Matching on the trailing path segment catches a wrapper
+ # left behind at an older storage location, while the escaped dot and the
+ # trailing boundary keep a co-installed agent's wrapper
+ # (start-pulse-agent-prod.sh) out of the match.
+ pkill -f "/start-pulse-agent\.sh([[:space:]]|$)" 2>/dev/null || true
# Use process name matching to avoid killing unrelated processes. The
# trailing boundary keeps a co-installed agent whose binary name starts
# with this one (pulse-agent vs pulse-agent-prod) out of the match.
diff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.go
index d1b6b76a46..3330750b0a 100644
--- a/scripts/installtests/install_sh_test.go
+++ b/scripts/installtests/install_sh_test.go
@@ -5147,3 +5147,78 @@ func TestInstallSHAgentKillPatternSparesSiblingAgent(t *testing.T) {
t.Error("bounded pattern must not match pulse-agent-prod")
}
}
+
+// TestInstallSHUnraidStopsWatchdogBeforeAgent guards a real incident: the
+// Unraid install path killed the agent but never the wrapper supervising it,
+// then started a second wrapper at the end of the install. The survivor and
+// the newcomer both loop trying to own the same agent id, and because the old
+// wrapper is a watchdog it can respawn the agent during the install window
+// using the previous binary and arguments.
+func TestInstallSHUnraidStopsWatchdogBeforeAgent(t *testing.T) {
+ content, err := os.ReadFile(repoFile("scripts", "install.sh"))
+ if err != nil {
+ t.Fatalf("read install.sh: %v", err)
+ }
+ script := string(content)
+
+ start := strings.Index(script, "if [[ -f /etc/unraid-version ]]; then")
+ if start < 0 {
+ t.Fatal("could not locate the Unraid install branch")
+ }
+ endOffset := strings.Index(script[start:], "\n# 4.")
+ if endOffset < 0 {
+ endOffset = len(script) - start
+ }
+ unraid := script[start : start+endOffset]
+
+ wrapperKill := strings.Index(unraid, `pkill -f "/start-pulse-agent\.sh`)
+ if wrapperKill < 0 {
+ t.Fatal("Unraid install must stop the existing wrapper supervisor, or its watchdog survives the install and races the new one")
+ }
+ agentKill := strings.Index(unraid, `pkill -f "^${RUNTIME_BINARY}`)
+ if agentKill < 0 {
+ t.Fatal("Unraid install must stop the existing agent")
+ }
+ if wrapperKill > agentKill {
+ t.Error("the wrapper supervisor must be stopped before the agent, otherwise the watchdog respawns the agent during the install")
+ }
+}
+
+// TestInstallSHWatchdogKillPatternSparesSiblingWrapper proves the wrapper
+// pattern discriminates, so stopping this agent's supervisor never stops a
+// co-installed agent's supervisor on the same host.
+func TestInstallSHWatchdogKillPatternSparesSiblingWrapper(t *testing.T) {
+ const (
+ targetCmd = "bash /boot/config/plugins/pulse-agent/start-pulse-agent.sh"
+ siblingCmd = "bash /boot/config/plugins/pulse-agent-prod/start-pulse-agent-prod.sh"
+ )
+
+ ereMatches := func(t *testing.T, pattern, line string) bool {
+ t.Helper()
+ cmd := exec.Command("grep", "-E", "-q", pattern)
+ cmd.Stdin = strings.NewReader(line + "\n")
+ err := cmd.Run()
+ if err == nil {
+ return true
+ }
+ var exitErr *exec.ExitError
+ if errors.As(err, &exitErr) && exitErr.ExitCode() == 1 {
+ return false
+ }
+ t.Fatalf("grep -E %q: %v", pattern, err)
+ return false
+ }
+
+ pattern := `/start-pulse-agent\.sh([[:space:]]|$)`
+ if !ereMatches(t, pattern, targetCmd) {
+ t.Error("wrapper pattern must match this agent's own supervisor")
+ }
+ if ereMatches(t, pattern, siblingCmd) {
+ t.Error("wrapper pattern must not match a co-installed agent's supervisor")
+ }
+
+ // Premise check: an unescaped dot is what makes this worth pinning.
+ if !ereMatches(t, "start-pulse-agent.sh", targetCmd) {
+ t.Fatal("premise check failed: the loose pattern is supposed to match the target")
+ }
+}