Report failing helper units, held packages and unloaded microcode #31

Merged
patrick merged 4 commits from feat/helper-unit-health into main 2026-11-01 20:33:32 +00:00
Owner

Why

kernelwatch-apt-update.service failed every hour on most hosts for weeks
(fixed in #30) and nothing showed it: the agent only Wants= its helper units,
so reports kept going out with stale data. This makes that kind of failure
visible, and covers two more ways a host can look current when it isn't.

Changes (agent 0.10.0)

  1. Helper unit failures. kernelwatch-apt-update and
    kernelwatch-needrestart run a new kernelwatch-unit-result script as
    their ExecStopPost=. It records each run's result and how many runs in a
    row have failed in /run/kernelwatch/<name>.result. 1–2 failures: a note.
    3 in a row (about 3h): update, naming the unit, its exit status and
    journalctl -u. Livepatch isn't tracked: its unit fails by design when the
    snap is installed but Livepatch isn't enabled, and it has its own check.
    New "kernelwatch helpers" row on the host page.
  2. Packages on hold. Installed hold packages are reported. A held
    linux-* package puts the host in update, since apt's simulation never
    lists it. Other holds get a note.
  3. CPU microcode. needrestart's nstalled but
    not loaded) puts the host in reboot. Livepatch doesn't cover it. Bare
    metal only; needrestart skips the

Deploying

Update the server first, then agente installer adds /usr/local/sbin/kernelwatch-unit-result` along with the updated units.

🤖 Generated with Claude Code

## Why kernelwatch-apt-update.service failed every hour on most hosts for weeks (fixed in #30) and nothing showed it: the agent only `Wants=` its helper units, so reports kept going out with stale data. This makes that kind of failure visible, and covers two more ways a host can look current when it isn't. ## Changes (agent 0.10.0) 1. **Helper unit failures.** `kernelwatch-apt-update` and `kernelwatch-needrestart` run a new `kernelwatch-unit-result` script as their `ExecStopPost=`. It records each run's result and how many runs in a row have failed in `/run/kernelwatch/<name>.result`. 1–2 failures: a note. 3 in a row (about 3h): `update`, naming the unit, its exit status and `journalctl -u`. Livepatch isn't tracked: its unit fails by design when the snap is installed but Livepatch isn't enabled, and it has its own check. New "kernelwatch helpers" row on the host page. 2. **Packages on hold.** Installed `hold` packages are reported. A held `linux-*` package puts the host in `update`, since apt's simulation never lists it. Other holds get a note. 3. **CPU microcode.** needrestart's nstalled but not loaded) puts the host in `reboot`. Livepatch doesn't cover it. Bare metal only; needrestart skips the ## Deploying Update the server first, then `agente installer adds `/usr/local/sbin/kernelwatch-unit-result` along with the updated units. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
patrick added 3 commits 2026-11-01 20:27:50 +00:00
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>
A held package never upgrades, and apt's simulation leaves it out, so
its updates (security ones included) appear nowhere. A leftover hold on
linux-image-amd64 or linux-generic keeps a host on its kernel while it
looks current.

The agent reports installed held packages (dpkg's "hi") as
held_packages. A held linux-* package puts the host in update with the
apt-mark unhold hint; other holds, usually deliberate, get a note. The
host page lists them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Put hosts with unloaded CPU microcode updates in reboot
CI / tests (Python 3.10) (pull_request) Successful in 40s
CI / tests (Python 3.11) (pull_request) Successful in 39s
CI / tests (Python 3.12) (pull_request) Successful in 38s
CI / tests (Python 3.13) (pull_request) Successful in 38s
CI / lint (pull_request) Failing after 3s
8174f1df81
On bare metal, needrestart -b reports NEEDRESTART-UCSTA: 2 when the
installed intel-microcode/amd64-microcode is newer than what the CPU
loaded at boot, which only a reboot fixes. The agent dropped those
lines. It now reports needrestart_ucsta, _uccur and _ucexp, and the
server puts the host in reboot with both revisions. Livepatch doesn't
cover it. needrestart skips the check in VMs, so only physical hosts
(debian-homelab today) report it; the host page gets a "CPU microcode"
row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
patrick added 1 commit 2026-11-01 20:31:11 +00:00
Fix shellcheck SC1007 in helper_units
CI / tests (Python 3.11) (pull_request) Successful in 39s
CI / tests (Python 3.10) (pull_request) Successful in 39s
CI / tests (Python 3.12) (pull_request) Successful in 40s
CI / tests (Python 3.13) (pull_request) Successful in 39s
CI / lint (pull_request) Successful in 3s
1b6cfce18b
`local x=` reads to shellcheck like a mistyped assignment; spell the empty
values as ''.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
patrick merged commit 8710584446 into main 2026-11-01 20:33:32 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: patrick/kernel-automation#31