Report when kernelwatch's own helper units keep failing

kernelwatch-apt-update.service failed hourly on most hosts for weeks
without anything showing it. The agent only Wants= its helper units, so
the report goes out regardless, with stale lists or (for needrestart)
results that quietly turn "unknown".

Each helper (apt-update, needrestart) now runs kernelwatch-unit-result
as its ExecStopPost=, which systemd runs after failed runs too. It
writes "RESULT EXIT_CODE EXIT_STATUS FAILURES" to
/run/kernelwatch/<name>.result, FAILURES counting failed runs in a row.
The agent (0.10.0) reports results from the last two hours as
helper_units. On the server, one or two failures are a note (an admin's
apt can hold the lock now and then); three in a row put the host in
update, naming the unit and its exit status and pointing at journalctl.
The host page gets a "kernelwatch helpers" row.

The Livepatch unit isn't tracked: it fails by design where the snap is
installed but Livepatch isn't enabled, and Livepatch has its own check.

The apt-update unit now has RuntimeDirectory=kernelwatch (preserved,
like the others) for its result file.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-11-01 15:23:05 -05:00
1 parent ad310a4948
commit f88261d2f5
18 files changed
+303 -8

No files matched your search

+26
View File
@@ -405,6 +405,32 @@ class EvaluateTest(unittest.TestCase):
s = self.sec(age=10 * 86400, suite="jammy-security", os_id="ubuntu", os_version_id="22.04")
self.assertEqual(s.level, "update")
def test_helper_units_healthy(self):
s = self.level(report(helper_units=["apt-update success exited 0 0", "needrestart success exited 0 0"]))
self.assertEqual((s.level, s.reasons), ("ok", []))
def test_helper_unit_failing_once_is_a_note(self):
s = self.level(report(helper_units=["apt-update exit-code exited 100 1"]))
self.assertEqual(s.level, "ok")
self.assertEqual(s.reasons, ["kernelwatch-apt-update.service failed its last run (exit status 100); "
"see journalctl -u kernelwatch-apt-update.service"])
def test_helper_unit_failing_repeatedly_is_a_problem(self):
s = self.level(report(helper_units=["apt-update exit-code exited 100 3",
"needrestart timeout killed TERM 5"]))
self.assertEqual(s.level, "update")
self.assertEqual(s.reasons, [
"kernelwatch-apt-update.service failed its last 3 runs (exit status 100); "
"see journalctl -u kernelwatch-apt-update.service",
"kernelwatch-needrestart.service failed its last 5 runs (timeout, signal TERM); "
"see journalctl -u kernelwatch-needrestart.service"])
def test_helper_units_odd_entries_ignored(self):
s = self.level(report(helper_units=["apt-update exit-code", "x y z w many"]))
self.assertEqual((s.level, s.reasons), ("ok", []))
s = self.level(report(helper_units=["needrestart resources - - 4"]))
self.assertIn("kernelwatch-needrestart.service failed its last 4 runs (resources)", s.reasons[0])
def uu(self, success=6 * 3600, run=6 * 3600, state="enabled", **kw):
return self.level(report(unattended_upgrades=state, unattended_upgrades_success_age_seconds=success,
unattended_upgrades_run_age_seconds=run, **kw))