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.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
Admit silent unit absence without losing inventory failures
pulse-triage[bot]b3b368c21bf3
diff --git a/docs/release-control/v6/internal/subsystems/deployment-installability.md b/docs/release-control/v6/internal/subsystems/deployment-installability.mdindex 1017f993b5..76208eb687 100644--- a/docs/release-control/v6/internal/subsystems/deployment-installability.md+++ b/docs/release-control/v6/internal/subsystems/deployment-installability.md@@ -73,6 +73,26 @@ partial, malformed, duplicate, impostor or unknown-state inventory does not.This avoids an early pipe close hiding an installed legacy service under`pipefail`. Discovery itself never stops, enables or unmasks a unit.+Successful absence is what systemd reports on a fresh host: `systemctl+list-unit-files` exits 1 and prints nothing, on stdout or stderr, when none of+the named unit files exist. The installer, the unattended updater and the+auto-update mask check share one inventory read that accepts exactly that+silent exit 1 as an empty inventory from one complete combined stdout/stderr+read. A timeout, a signal, any other status, or an exit 1 that carries+output or a message remains a failed inventory. The fixture doubles must model+that status: a silent exit 1 is absence, an exit 1 with a message is failure,+and `systemctl --root` over an empty unit root exercises the real status. A+double that reports absence as exit 0 hides the defect that made every fresh+install refuse. A failed first observation must not be replaced by a later+silent read: both producers retain its message and refuse without querying+again. The registered installer and unattended-updater Go fixture hooks keep+the fresh-host, failed-first-read, other-silent-status and nonempty-blank-line+controls mandatory; command substitution must not trim a nonempty failed read+into apparent silence. Both readers retain the fixed five-second deadline and+one-second kill grace. No extra query or retry is introduced.+The installer hook still exercises the real empty systemctl fixture where+available. This does not establish native installation or an LXC stop cause.+The standalone unattended updater uses the same bounded name/state admissionbefore passing its explicit service identity to the installer. It checks thecommand-substitution result separately from local variable declaration, anddiff --git a/install.sh b/install.shindex d05155d758..d1ee9ab5ef 100755--- a/install.sh+++ b/install.sh@@ -750,6 +750,24 @@ recover_pulse_after_failed_replacement() {fi}+# Read the unit-file inventory for exact unit names. systemd exits 1 and prints+# nothing at all, on stdout or stderr, when none of the named unit files exist,+# which is every fresh host. That is an empty inventory. A timeout, a signal,+# another failed status, or exit 1 with output or a message remains a failure.+# Capture both streams in the same read:+# a later silent sample must never discard an earlier diagnostic.+unit_file_inventory() {+ local out="" rc=0+ # Keep trailing newlines: an emitted blank line is not a silent exit 1.+ out=$(LC_ALL=C timeout -k 1 5 systemctl list-unit-files --no-legend --no-pager --full -- "$@" 2>&1; rc=$?; printf '.'; exit "$rc") || rc=$?+ out="${out%.}"+ if (( rc == 1 )) && [[ -z "$out" ]]; then+ rc=0+ fi+ printf '%s' "$out"+ return "$rc"+}+# Detect existing service name (pulse or pulse-backend)detect_service_name() {if [[ "$SERVICE_NAME_EXPLICIT" == "true" ]]; then@@ -767,7 +785,7 @@ detect_service_name() {# grep -q closes a full inventory early: systemctl can report Broken pipe,# and pipefail then hides a real pulse-backend unit behind the default.# Consume one bounded inventory of the two exact historical names instead.- if ! unit_files=$(LC_ALL=C timeout -k 1 5 systemctl list-unit-files --no-legend --no-pager --full -- pulse-backend.service pulse.service 2>/dev/null); then+ if ! unit_files=$(unit_file_inventory pulse-backend.service pulse.service); thenprint_error "Cannot identify the Pulse systemd service: unit inventory failed. Reconcile service state before retrying." >&2return 1fi@@ -4521,7 +4539,7 @@ auto_update_units_refreshable() {timer_unit="$(basename "$timer_path")"service_unit="$(basename "$service_path")"if ! command -v systemctl >/dev/null 2>&1 ||- ! unit_files=$(LC_ALL=C timeout -k 1 5 systemctl list-unit-files --no-legend --no-pager --full -- "$timer_unit" "$service_unit" 2>/dev/null); then+ ! unit_files=$(unit_file_inventory "$timer_unit" "$service_unit"); thenprint_warn "Cannot confirm auto-update unit masks; preserving the existing helper and units."return 1fidiff --git a/scripts/installtests/install_sh_test.go b/scripts/installtests/install_sh_test.goindex d1de72ef47..1feefce099 100644--- a/scripts/installtests/install_sh_test.go+++ b/scripts/installtests/install_sh_test.go@@ -4569,6 +4569,19 @@ func TestRootInstallServiceDiscoveryFailsClosedWithoutShortReads(t *testing.T) {if err != nil {t.Fatalf("installer service discovery/caller controls: %v\n%s", err, out)}+ // Do not let deleting a fresh-host or failure-retention control silently+ // leave this all-method fixture green. Real systemctl remains optional on+ // platforms without it; the portable production-function controls do not.+ for _, name := range []string{+ "test_fresh_host_no_matching_unit_files_is_an_empty_inventory",+ "test_first_inventory_failure_is_not_replaced_by_silent_absence",+ "test_only_silent_exit_one_is_admitted_as_absence",+ "test_blank_line_output_is_not_a_silent_failed_inventory",+ } {+ if !strings.Contains(string(out), name+" (__main__.ServiceDiscovery."+name+") ... ok") {+ t.Fatalf("required service inventory control %s did not pass:\n%s", name, out)+ }+ }}func TestRootInstallStableReleaseTagRejectsPrereleaseShapes(t *testing.T) {diff --git a/scripts/installtests/pulse_auto_update_test.go b/scripts/installtests/pulse_auto_update_test.goindex d2bf7dfa42..2d640bc8b8 100644--- a/scripts/installtests/pulse_auto_update_test.go+++ b/scripts/installtests/pulse_auto_update_test.go@@ -115,6 +115,10 @@ func TestAutoUpdateServiceDiscoveryAndInstallerHandoff(t *testing.T) {ctx, cancel := context.WithTimeout(context.Background(), 45*time.Second)defer cancel()cmd := exec.CommandContext(ctx, "python3", repoFile("scripts", "tests", "test_server_service_discovery.py"), "-v",+ "ServiceDiscovery.test_fresh_host_no_matching_unit_files_is_an_empty_inventory",+ "ServiceDiscovery.test_first_inventory_failure_is_not_replaced_by_silent_absence",+ "ServiceDiscovery.test_only_silent_exit_one_is_admitted_as_absence",+ "ServiceDiscovery.test_blank_line_output_is_not_a_silent_failed_inventory","ServiceDiscovery.test_automatic_helper_preserves_exact_names_and_explicit_instances","ServiceDiscovery.test_automatic_helper_cannot_short_read_the_installer_handoff","ServiceDiscovery.test_automatic_helper_refuses_before_backup_or_installer_even_in_or_list",diff --git a/scripts/pulse-auto-update.sh b/scripts/pulse-auto-update.shindex 3601a9fb62..974f7cdb4b 100755--- a/scripts/pulse-auto-update.sh+++ b/scripts/pulse-auto-update.sh@@ -320,6 +320,24 @@ version_greater_than() {return 1 # v1 <= v2}+# Read the unit-file inventory for exact unit names. systemd exits 1 and prints+# nothing at all, on stdout or stderr, when none of the named unit files exist.+# That is an empty inventory. A timeout, a signal, another failed status, or+# exit 1 with output or a message remains a failure. Capture both streams in+# the same read: a later silent sample must+# never discard an earlier diagnostic.+unit_file_inventory() {+ local out="" rc=0+ # Keep trailing newlines: an emitted blank line is not a silent exit 1.+ out=$(LC_ALL=C timeout -k 1 5 systemctl list-unit-files --no-legend --no-pager --full -- "$@" 2>&1; rc=$?; printf '.'; exit "$rc") || rc=$?+ out="${out%.}"+ if (( rc == 1 )) && [[ -z "$out" ]]; then+ rc=0+ fi+ printf '%s' "$out"+ return "$rc"+}+# Detect service name (could be pulse or pulse-backend)detect_service_name() {if [[ -n "${PULSE_SERVICE_NAME:-}" ]]; then@@ -336,7 +354,7 @@ detect_service_name() {# Keep the standalone helper aligned with the server installer's bounded# discovery. Its explicit installer handoff must not carry a short-read# default past the installer's own discovery gate.- if ! unit_files=$(LC_ALL=C timeout -k 1 5 systemctl list-unit-files --no-legend --no-pager --full -- pulse-backend.service pulse.service 2>/dev/null); then+ if ! unit_files=$(unit_file_inventory pulse-backend.service pulse.service); thenlog error "Cannot identify the Pulse systemd service: unit inventory failed. Reconcile service state before retrying." >&2return 1fidiff --git a/scripts/tests/test_server_service_discovery.py b/scripts/tests/test_server_service_discovery.pyindex 32728f1bfa..60ee4e4dad 100644--- a/scripts/tests/test_server_service_discovery.py+++ b/scripts/tests/test_server_service_discovery.py@@ -24,6 +24,8 @@ UPDATER = Path(os.environ.get("PULSE_AUTO_UPDATER_UNDER_TEST", ROOT / "scripts/pREAL_SYSTEMCTL = shutil.which("systemctl")QUERY = ["list-unit-files", "--no-legend", "--no-pager", "--full", "--","pulse-backend.service", "pulse.service"]+# What systemctl prints when the listing itself fails, as opposed to matching nothing.+FAILED_LISTING = "Failed to get unit file list: No such file or directory\n"SYSTEMCTL = r'''#!/usr/bin/env python3import json, os, sys, time@@ -37,6 +39,10 @@ if args[0] == "list-unit-files":if mode == "real":os.execv(os.environ["REAL_SYSTEMCTL"],[os.environ["REAL_SYSTEMCTL"], "--root=" + str(f / "root")] + args)+ if mode == "first-error-then-absent":+ if len((f / "calls").read_text().splitlines()) == 1:+ os.write(2, b"Failed to get unit file list: Input/output error\n")+ sys.exit(1)if mode == "hang":time.sleep(30)if mode == "large":@@ -53,6 +59,8 @@ if args[0] == "list-unit-files":os._exit(1)sys.exit(0)os.write(1, os.environ["ROWS"].encode())+ if os.environ.get("ERR"):+ os.write(2, os.environ["ERR"].encode())sys.exit(int(os.environ["QUERY_EXIT"]))if args[0] == "show":state = "inactive" if (f / "stopped").exists() else "active"@@ -192,7 +200,7 @@ exit "$status"class ServiceDiscovery(unittest.TestCase):def run_fixture(self, *, rows="", mode="rows", query_exit=0, flow="query", explicit=None,- producer="installer"):+ producer="installer", err="", units_present=True):with tempfile.TemporaryDirectory(prefix="pulse-service-discovery-") as directory:f = Path(directory)for name in ["bin", "install/bin", "config", "units", "root/etc/systemd/system"]:@@ -221,12 +229,14 @@ class ServiceDiscovery(unittest.TestCase):body = source[start:end].replace("/etc/systemd/system/", str(f / "units") + "/")(f / "unit-writer.sh").write_text(body)unit = "[Unit]\nDescription=Fixture only\n[Service]\nExecStart=/bin/true\n"- (f / "root/etc/systemd/system/pulse-backend.service").write_text(unit)- (f / "root/etc/systemd/system/pulse.service").write_text(unit)+ if units_present:+ (f / "root/etc/systemd/system/pulse-backend.service").write_text(unit)+ (f / "root/etc/systemd/system/pulse.service").write_text(unit)env = {k: v for k, v in os.environ.items() if not k.startswith("PULSE_")}env.update(FIXTURE=str(f), INSTALLER=str(INSTALLER), UPDATER=str(UPDATER),PRODUCER=producer, FLOW=flow, MODE=mode,- ROWS=rows, QUERY_EXIT=str(query_exit), REAL_SYSTEMCTL=REAL_SYSTEMCTL or "",+ ROWS=rows, QUERY_EXIT=str(query_exit), ERR=err,+ REAL_SYSTEMCTL=REAL_SYSTEMCTL or "",PATH=str(f / "bin") + os.pathsep + os.environ["PATH"],PULSE_INSTALL_DIR=str(f / "install"), PULSE_CONFIG_DIR=str(f / "config"),PULSE_BINARY_LINK_PATH=str(f / "pulse-link"))@@ -290,9 +300,47 @@ class ServiceDiscovery(unittest.TestCase):self.assertEqual(e["calls"], [])def test_partial_failed_inventory_is_not_absence(self):- for rows in ["", "pulse-backend.service enabled enabled\n", "pulse.service disabled enabled\n"]:- with self.subTest(rows=rows):- self.assert_refused(self.run_fixture(rows=rows, query_exit=1))+ failure = "Failed to get unit file list: No such file or directory\n"+ for rows, err in [("", failure), ("pulse-backend.service enabled enabled\n", ""),+ ("pulse.service disabled enabled\n", ""),+ ("pulse-backend.service enabled enabled\n", failure)]:+ with self.subTest(rows=rows, err=err):+ self.assert_refused(self.run_fixture(rows=rows, err=err, query_exit=1))++ def test_first_inventory_failure_is_not_replaced_by_silent_absence(self):+ for producer in ("installer", "updater"):+ with self.subTest(producer=producer):+ e = self.run_fixture(producer=producer, mode="first-error-then-absent")+ self.assert_refused(e)+ self.assertEqual(e["calls"], [QUERY],+ "A failed read must not be replaced by a second sample")++ def test_only_silent_exit_one_is_admitted_as_absence(self):+ for producer in ("installer", "updater"):+ for code in (2, 124, 137):+ with self.subTest(producer=producer, code=code):+ e = self.run_fixture(producer=producer, query_exit=code)+ self.assert_refused(e)+ self.assertEqual(e["calls"], [QUERY])++ def test_blank_line_output_is_not_a_silent_failed_inventory(self):+ for producer in ("installer", "updater"):+ for rows, err in (("\n", ""), ("", "\n"), ("\n\n", "\n")):+ with self.subTest(producer=producer, rows=rows, err=err):+ e = self.run_fixture(producer=producer, rows=rows, err=err, query_exit=1)+ self.assert_refused(e)+ self.assertEqual(e["calls"], [QUERY])++ def test_fresh_host_no_matching_unit_files_is_an_empty_inventory(self):+ # systemd exits 1 and prints nothing when none of the named unit files exist, which is+ # every fresh host. The installer and the update helper must both select the default.+ for producer in ("installer", "updater"):+ with self.subTest(producer=producer):+ e = self.run_fixture(producer=producer, query_exit=1)+ self.assertEqual(e["result"].returncode, 0, e["result"].stderr)+ self.assertEqual(e["result"].stdout, "SERVICE=pulse\n")+ # Absence is decided from one complete stdout/stderr observation.+ self.assertEqual(e["calls"], [QUERY])def test_malformed_duplicate_impostor_and_unknown_inventory_stop(self):for rows in ["pulse-backendXservice enabled\n", "pulse-backend.service.extra enabled\n",@@ -315,14 +363,15 @@ class ServiceDiscovery(unittest.TestCase):self.assertEqual(e["result"].stdout, "SERVICE=pulse-backend\n")def test_failed_discovery_is_distinct_from_no_installation(self):- e = self.run_fixture(flow="existing", query_exit=1)+ e = self.run_fixture(flow="existing", query_exit=1,+ err="Failed to get unit file list: No such file or directory\n")self.assert_refused(e)self.assertEqual(e["result"].returncode, 2)def test_all_mutating_callers_refuse_when_errexit_is_disabled(self):for flow in ["main", "late-main", "archive", "build", "uninstall", "reset", "unit", "ensure-unit"]:with self.subTest(flow=flow):- self.assert_refused(self.run_fixture(flow=flow, query_exit=1))+ self.assert_refused(self.run_fixture(flow=flow, query_exit=1, err=FAILED_LISTING))def test_archive_and_source_paths_stop_only_the_selected_legacy_unit(self):for flow in ["archive", "build"]:@@ -335,6 +384,14 @@ class ServiceDiscovery(unittest.TestCase):self.assertFalse(e["broken_pipe"])@unittest.skipUnless(REAL_SYSTEMCTL, "systemctl unavailable")+ def test_real_systemctl_on_a_host_without_pulse_units_selects_the_default(self):+ # Real systemctl, empty unit root: the genuine exit status for "nothing matched".+ for producer in ("installer", "updater"):+ with self.subTest(producer=producer):+ e = self.run_fixture(mode="real", producer=producer, units_present=False)+ self.assertEqual(e["result"].returncode, 0, e["result"].stderr)+ self.assertEqual(e["result"].stdout, "SERVICE=pulse\n")+def test_real_systemctl_fixture_inventory_has_compatible_rows(self):e = self.run_fixture(mode="real")self.assertEqual(e["result"].returncode, 0, e["result"].stderr)@@ -368,7 +425,8 @@ class ServiceDiscovery(unittest.TestCase):("pulse-backendXservice enabled\n", 0),("pulse.service enabled enabled extra\n", 0)]:with self.subTest(rows=rows, status=status):- e = self.run_fixture(producer="updater", rows=rows, query_exit=status, flow="automatic")+ e = self.run_fixture(producer="updater", rows=rows, query_exit=status, flow="automatic",+ err=FAILED_LISTING if (rows, status) == ("", 1) else "")self.assert_refused(e)self.assertIsNone(e["installer_service"])diff --git a/scripts/tests/test_server_update_repair.py b/scripts/tests/test_server_update_repair.pyindex 5b6ebe1ef1..3f24e9cebd 100644--- a/scripts/tests/test_server_update_repair.py+++ b/scripts/tests/test_server_update_repair.py@@ -30,8 +30,9 @@ with (f / "manager-calls").open("a") as out:out.write(json.dumps(args) + "\n")if args == ["list-unit-files", "--no-legend", "--no-pager", "--full", "--","pulse-backend.service", "pulse.service"]:- # Complete known absence permits recreating the missing default unit.- sys.exit(0)+ # Model systemd's actual empty-root status. Absence must permit recreating+ # the missing default unit, not fail the existing-install recovery path.+ sys.exit(1)if args == ["daemon-reload"]:sys.exit(0)sys.exit(97)diff --git a/scripts/tests/test_server_update_timer.py b/scripts/tests/test_server_update_timer.pyindex 7d0ad7291d..f605dc0264 100644--- a/scripts/tests/test_server_update_timer.py+++ b/scripts/tests/test_server_update_timer.py@@ -32,6 +32,7 @@ case "$1" infiif [[ "$GUARD_INVENTORY" == hang ]]; then exec sleep 30; fiprintf '%s' "$GUARD_ROWS"+ printf '%s' "${GUARD_ERR:-}" >&2exit "$GUARD_EXIT"fiif [[ "$INVENTORY" == real ]]; then@@ -125,7 +126,7 @@ class ServerUpdateTimerTest(unittest.TestCase):def exercise(self, *, flow="query", state="enabled", service="pulse",rows=None, query_exit=0, inventory="double", mask="",config_enabled=True, mask_location="configured", guard_rows=None,- guard_exit=0, guard_inventory=None):+ guard_exit=0, guard_inventory=None, guard_err=""):with tempfile.TemporaryDirectory() as temporary:fixture = Path(temporary)config = fixture / "config"@@ -188,7 +189,7 @@ class ServerUpdateTimerTest(unittest.TestCase):guard_rows = f"{timer_name} {timer_state} enabled\n{service_name} {service_state} enabled\n"env = {**os.environ, "INSTALLER": str(INSTALLER), "FIXTURE": str(fixture),"FLOW": flow, "ROWS": rows, "QUERY_EXIT": str(query_exit),- "GUARD_ROWS": guard_rows, "GUARD_EXIT": str(guard_exit),+ "GUARD_ROWS": guard_rows, "GUARD_EXIT": str(guard_exit), "GUARD_ERR": guard_err,"GUARD_INVENTORY": guard_inventory or inventory,"INVENTORY": inventory, "REAL_SYSTEMCTL": REAL_SYSTEMCTL or "","PATH": f"{tools}:{os.environ['PATH']}", "PULSE_SERVICE_NAME": service,@@ -356,14 +357,16 @@ class ServerUpdateTimerTest(unittest.TestCase):self.assertIn("masked-runtime", e["result"].stdout)def test_failed_unknown_and_duplicate_effective_inventory_cannot_admit_writes(self):- for rows, code in (("pulse-update.timer disabled enabled\n", 1),- ("pulse-update.timer not-understood enabled\n", 0),- ("pulse-update.timer\n", 0),- ("pulse-updateXtimer disabled enabled\n", 0),- ("pulse-update.timer disabled enabled\npulse-update.timer disabled enabled\n", 0),- ("", 1)):- with self.subTest(rows=rows, code=code):- self.assert_preserved(self.exercise(flow="version", guard_rows=rows, guard_exit=code))+ failure = "Failed to get unit file list: No such file or directory\n"+ for rows, code, err in (("pulse-update.timer disabled enabled\n", 1, ""),+ ("pulse-update.timer not-understood enabled\n", 0, ""),+ ("pulse-update.timer\n", 0, ""),+ ("pulse-updateXtimer disabled enabled\n", 0, ""),+ ("pulse-update.timer disabled enabled\npulse-update.timer disabled enabled\n", 0, ""),+ ("", 1, failure)):+ with self.subTest(rows=rows, code=code, err=err):+ self.assert_preserved(self.exercise(flow="version", guard_rows=rows, guard_exit=code,+ guard_err=err))def test_effective_inventory_is_bounded_and_missing_systemctl_preserves_assets(self):self.assert_preserved(self.exercise(flow="version", guard_inventory="hang"))@@ -372,9 +375,12 @@ class ServerUpdateTimerTest(unittest.TestCase):self.assertEqual(e["calls"], [])def test_successful_absent_or_unmasked_inventory_keeps_asset_repair_working(self):- for rows in ("", "pulse-update.timer disabled enabled\npulse-update.service disabled enabled\n"):- with self.subTest(rows=rows):- self.assert_refreshed(self.exercise(flow="assets", state="disabled", guard_rows=rows), False)+ # systemd exits 1 and prints nothing when neither unit file exists: absence, not failure.+ for rows, code in (("", 0), ("", 1),+ ("pulse-update.timer disabled enabled\npulse-update.service disabled enabled\n", 0)):+ with self.subTest(rows=rows, code=code):+ self.assert_refreshed(self.exercise(flow="assets", state="disabled", guard_rows=rows,+ guard_exit=code), False)def test_effective_inventory_names_are_exact_full_custom_instance_names(self):service = "pulse-" + "department-" * 12