Files
kernel-automation/docs/how-it-works.md
T
patrickandClaude Opus 5.5 70272efed5
CI / tests (Python 3.10) (pull_request) Successful in 29s
CI / tests (Python 3.11) (pull_request) Successful in 30s
CI / tests (Python 3.12) (pull_request) Successful in 29s
CI / tests (Python 3.13) (pull_request) Successful in 28s
CI / lint (pull_request) Successful in 4s
Flag a /boot too full for the next kernel and packages dpkg left unfinished
A full /boot makes the next kernel's postinst fail: apt is left half-done
and the host quietly stays on its old kernel, which kernelwatch only
noticed indirectly, if at all. The agent now reports the size and free
space of the filesystem holding /boot (df) and the packages dpkg didn't
finish installing (half-installed, unpacked, half-configured, trigger
states or reinst-required, as dpkg --audit counts them).

The server puts a host in update when /boot has less than
boot_min_free_mb (default 200, 0 disables) free, or any package is
unfinished, with the fix in the reason ("run dpkg --configure -a"). The
host page shows both. Agents before 0.6.0 send neither field and are
judged as before. Agent 0.6.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-31 18:54:47 -04:00

7.7 KiB
Raw Blame History

How it works

← kernelwatch

How each host's status is decided, and how the agent collects the facts behind it.

Each host gets one status. When several apply, the worst one wins:

Status Meaning
stale No report in stale_after_hours (default 3h), or never. Other data can't be trusted.
reboot A newer kernel is installed but not running, or /run/reboot-required exists.
update A kernel or security update is available but not installed, services are running outdated libraries and need a restart, or apt's package lists are too old (apt_stale_after_hours) for "no updates" to mean anything. Also when /boot has less than boot_min_free_mb free, or dpkg left packages half-installed.
ok Running the newest installed kernel, with no security or kernel updates pending.

Each row also lists the reasons behind its status, and clicking a host shows its full report and recent history.

How the agent works it out:

  • Running vs. installed kernel, three ways:
    • A newer linux-image-* installed than uname -r means a version upgrade.
    • The build in uname -v (Debian 6.12.57-1, #85-Ubuntu, #33~24.04.1-Ubuntu) is compared with the installed package version of the running kernel (6.12.57-1, 6.8.0-85.85, 6.14.0-33.33~24.04.1). A mismatch means the package was upgraded in place after boot; uname -r didn't change, but a reboot is still needed.
    • needrestart's kernel result, for build strings the server doesn't recognise (see "Services needing a restart", below).
  • Services needing a restart (e.g. nginx still using the old OpenSSL after an upgrade): from needrestart -b, if it's installed. Ubuntu ships it; on Debian, install with install.sh --with-needrestart. Without it, the Services column shows ? and status isn't affected. needrestart has to inspect every process, so it runs as root in its own unit, kernelwatch-needrestart.service. That unit has no network access, only the two capabilities needrestart needs, and list-only mode, so it never restarts anything. It writes its results to /run/kernelwatch/needrestart, and the unprivileged agent unit runs it just before each report and reads the file. The agent never runs as root, and needrestart never gets network access. Fix it on the host: sudo needrestart -r a (or restart the listed services), and the next report clears it.
  • Ubuntu Livepatch: with Livepatch (free for personal use with Ubuntu Pro), a newer kernel being installed doesn't mean the running one is unpatched. If Livepatch is healthy (applied or nothing-to-apply, checked, supported), a pending kernel reboot, or a /run/reboot-required caused only by linux-* packages, shows as a note instead of reboot, and the note gives the date by which the kernel must be upgraded. Livepatch only fixes high and critical CVEs, and only until that date, so cover ends 14 days before it and the host goes to reboot as usual. Any other reboot reason (libc, systemd) still counts. If Livepatch is failing, unsupported or in a state we don't know, the host gets no cover and the reason is noted, and after livepatch_alert_after_hours you get an ntfy alert. Hosts without Livepatch are unaffected. canonical-livepatch needs root and a snap cgroup, so like needrestart it runs in its own unit, kernelwatch-livepatch.service, which writes /run/kernelwatch/livepatch before each report. It's skipped when the snap isn't installed.
  • Agent version: each report includes it. Hosts running an older agent than the server shipped with get a note to run agent/deploy.sh; their status isn't changed.
  • Hostname check: each report includes the host's own name. If its first DNS label differs from the name the host is registered under (ignoring case), the row gets a note: "registered as web01 but reports itself as db01". This catches a token copied to the wrong machine. It never changes the status. A host you registered under a custom label (<ssh target> <name> in agent/hosts) shows the note until you tell its agent which name to report: agent/deploy.sh iris -- --report-hostname iris (or install.sh --report-hostname iris on the host, which sets REPORT_HOSTNAME in agent.conf). Upgrades and --rotate keep it; --default-report-hostname removes it. That's the host's own say-so, so it only silences the note for hosts you've deliberately named.
  • Available updates: a simulated apt-get dist-upgrade. It is read-only, takes no locks and writes no cache files. dist-upgrade is used so that new-ABI kernel packages pulled in by the meta-package show up. Lines whose origin contains -security count as security updates. If the simulation fails (unmet dependencies, a broken sources entry, a damaged package cache), apt prints no updates at all, so the agent reports the counts as unknown along with apt's error, and the host goes to update with "apt can't work out pending updates". Agents before 0.5.0 can't tell a failure from "no updates".
  • Room for the next kernel: each kernel adds an image and an initramfs to /boot, often over 100 MB together. When /boot fills up, the new kernel's install fails half-way, apt is left broken, and the host quietly stays on its old kernel. The agent reports the size and free space of the filesystem holding /boot (from df; the root filesystem when /boot isn't separate). Under boot_min_free_mb (default 200) free puts the host in update with "/boot has N MB free". Fix it on the host: sudo apt autoremove --purge removes old kernels.
  • Unfinished packages: packages dpkg didn't finish installing, read from its status database (the same states dpkg --audit reports: half-installed, unpacked, half-configured, waiting on triggers, or reinst-required). These are usually left by a failed install script, often because /boot was full. They put the host in update with "N packages not fully installed". Fix it on the host: sudo dpkg --configure -a (after freeing space, if that was the cause). A report taken while apt is mid-install can show this briefly; the next one clears it. Agents before 0.6.0 send neither field and are judged as before.
  • Fresh package lists: the simulation only knows what apt's package lists say, and the agent can't refresh them itself. Ubuntu refreshes them about once a day. Debian doesn't by default unless unattended-upgrades is set up, so a new kernel or security update can stay invisible until someone runs apt update. Install with --with-apt-update and kernelwatch-apt-update.service runs apt-get update just before each report, so updates show up within the hour. Either way, lists older than apt_stale_after_hours put the host in update.
  • Phased updates (Ubuntu only): Ubuntu rolls some updates out gradually and holds them back from a share of machines at first. apt doesn't offer these to the host yet, so they aren't counted as available updates. They appear as their own Phased column (hover for the packages, – on Debian), with the list also on the host page. They never affect status, because Ubuntu doesn't phase security updates and there's nothing to act on until apt offers them.
  • Package list freshness: the mtime of apt's update stamps. The agent doesn't run apt update itself; it relies on the stock apt-daily.timer. If that's disabled, the host shows update with "package lists N days old".

The agent sends raw facts and the server decides what they mean, so you can change the status rules without touching the agents.