Files
kernel-automation/docs/how-it-works.md
T
patrickandClaude Opus 5.5 15b1f5be4f
CI / tests (Python 3.10) (pull_request) Successful in 43s
CI / tests (Python 3.11) (pull_request) Successful in 44s
CI / tests (Python 3.12) (pull_request) Successful in 43s
CI / tests (Python 3.13) (pull_request) Successful in 42s
CI / lint (pull_request) Successful in 3s
Flag hosts without room on disk for their pending upgrades
A filesystem that fills up while apt downloads or dpkg unpacks leaves the
upgrade half-done and apt broken, the same failure as a full /boot but on
/ or /var. Nothing caught it until the host's updates stopped.

The agent (0.11.0) now works out what the pending upgrades need. A
simulation doesn't print apt's "Need to get" or "additional disk space"
lines, so it sums the package records from apt-cache show for each version
the simulation would install: Size for each .deb not already in
/var/cache/apt/archives, and the growth in Installed-Size over the
installed versions (from dpkg-query). Removals aren't subtracted, so it
errs high. It also reports free space and the mount point of the
filesystems holding /var/cache/apt/archives and /usr.

The server puts a host in update when the upgrades would leave less than
upgrade_min_free_mb (default 100, 0 disables) on either filesystem. The
download and the install both count when they're on the same one. With
nothing pending there is nothing to check, so this doesn't turn into
general disk monitoring. The host page gets a "Pending upgrades size" row.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 20:16:54 -05:00

16 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, /run/reboot-required exists, or newer CPU microcode is installed but not loaded.
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, the pending upgrades would leave less than upgrade_min_free_mb free where apt downloads or installs them, dpkg left packages half-installed, a kernel package is on hold, the OS release no longer gets security updates, unattended-upgrades is enabled but hasn't succeeded in unattended_upgrades_stale_after_days, the release's security repository is missing from apt or hasn't refreshed in security_repo_stale_after_days, or one of kernelwatch's own helper units has failed three runs in a row.
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.
  • CPU microcode: on bare metal, needrestart also compares the microcode revision the CPU loaded at boot with the one the installed intel-microcode or amd64-microcode package provides. A newer one only loads on a reboot, so it puts the host in reboot: "CPU microcode update installed but not loaded (0x001e → 0x0020)". Livepatch doesn't cover it. needrestart skips the check in virtual machines (the hypervisor handles microcode), so the host page's "CPU microcode" row only appears on physical hosts. Agents before 0.10.0 don't report 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.
  • kernelwatch's own helpers: kernelwatch-apt-update.service and kernelwatch-needrestart.service run as root just before each report. The agent only Wants= them, so if they fail the report still goes out, with stale lists or no needrestart results, and nothing would say why. So each one records how its run ended (ExecStopPost=kernelwatch-unit-result, in /run/kernelwatch/<name>.result), counting failures in a row, and the agent reports it. One or two failures are a note, since one run can fail now and then (an admin's apt holding the lock). Three in a row, about three hours, put the host in update: "kernelwatch-apt-update.service failed its last 3 runs (exit status 100); see journalctl -u kernelwatch-apt-update.service". The host page's "kernelwatch helpers" row shows each one. 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. Agents before 0.10.0 don't report it.
  • 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.
  • Room for the pending upgrades: if a filesystem fills up while apt downloads or dpkg unpacks, the upgrade stops half-way and apt is left broken, as with a full /boot. Under unattended-upgrades, nobody is watching when it happens. A simulation doesn't print apt's "Need to get" and "additional disk space" figures, so the agent works them out from the package records (apt-cache show for each version the simulation would install). The download is the Size of each .deb not already in /var/cache/apt/archives; unattended-upgrades often downloads ahead. The install is the growth in Installed-Size: the new versions' minus the installed ones', or all of it for new packages. Packages the upgrade would remove aren't subtracted, so the estimate errs high. The agent also reports free space and the mount point of the filesystems holding /var/cache/apt/archives and /usr. If they're the same filesystem, the download and the install both count against it. A filesystem the upgrades would leave with less than upgrade_min_free_mb (default 100) free puts the host in update with "pending upgrades need N MB on /var (...), M MB free". Nothing pending means nothing to check, however full the disk is. kernelwatch doesn't monitor disk usage in general; use your usual monitoring for that. Fix it on the host: sudo apt clean empties the download cache, and sudo apt autoremove --purge removes old kernels' modules from /usr/lib/modules. Agents before 0.11.0 don't report it.
  • 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.
  • Packages on hold: installed packages marked hold (apt-mark hold, or dpkg's selection), from dpkg's status database. apt never upgrades them, and the simulation doesn't list them, so their updates (security ones included) don't show up anywhere else. A held linux-* package (linux-image-amd64, linux-generic) would leave the host on its current kernel while looking up to date, so it puts the host in update; release it with sudo apt-mark unhold <package>. Other holds are usually deliberate and only get a note. The host page lists them all. Agents before 0.10.0 don't report holds.
  • OS end of support: once a release stops getting security updates, apt never offers one again, so the host would show ok indefinitely. The server knows when each supported release's free security support ends (server/kernelwatch/support.py): for Debian, the end of LTS, which carries on from regular security support through the same repository; for Ubuntu, the end of standard support, or with ESM (esm-infra, part of Ubuntu Pro, free for personal use) the end of ESM. The agent reads whether ESM is on from the Ubuntu Pro client's public status file, /var/lib/ubuntu-advantage/status.json. A host past its date is in update ("Debian 11 security support ended 2026-08-31"); in the os_eol_warn_days (default 90) before it, the row gets a note. An Ubuntu host with ESM enabled gets no warning when standard support ends, only before ESM does. The host page shows the dates. They're a table in the server, so they need a kernelwatch update when a new release ships; a release the table doesn't know is noted. Agents before 0.7.0 don't report ESM, so an Ubuntu host on one counts as having none.
  • unattended-upgrades: Ubuntu Server enables it by default, and when it breaks (a conffile prompt, a held package, a disabled timer) nothing shows until security updates pile up. For hosts where it's enabled (the package is installed and APT::Periodic::Unattended-Upgrade isn't 0; leftover config from a removed package doesn't count), the agent reports two timestamps from /var/lib/apt/periodic/: upgrade-stamp, which apt's daily job touches only when unattended-upgrades exits successfully, and unattended-upgrades-stamp, which unattended-upgrades writes whenever a run gets far enough, even if it then fails. No success in unattended_upgrades_stale_after_days (default 3) puts the host in update, and the reason says which way it broke: "is failing" (it runs, so read /var/log/unattended-upgrades/ on the host) or "hasn't run" (check systemctl status apt-daily-upgrade.timer). Packages it keeps back (held, blacklisted, waiting on a conffile prompt) from /var/lib/unattended-upgrades/kept-back are noted. Hosts where it's disabled or not installed aren't affected; the host page shows which. It assumes the stock apt-daily-upgrade.timer runs it: if you run unattended-upgrade from cron or Ansible instead, the stamp isn't updated, so set unattended_upgrades_stale_after_days = 0. Agents before 0.8.0 don't report it.
  • 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.
  • Security repository: security updates come from one suite, <codename>-security (trixie-security, noble-security). A host whose apt sources lack it sees "0 security updates" forever. One whose apt can't fetch it (an expired key, a wrong URL after a release upgrade, a mirror that fell behind) keeps the last copy while the update stamps and other lists move on. So the agent finds apt's list for that suite by its Suite:/Codename: field (file names depend on the mirror) and reports how old its Date: is, the newest copy if there are several mirrors. No list puts the host in update ("apt has no trixie-security repository"), and so does a copy older than security_repo_stale_after_days (default 7; both suites publish at least daily) while the package lists are otherwise fresh. If all the lists are old, only "package lists N days old" is shown. ESM suites aren't checked, as they publish rarely, and nor is a release past the end of support, whose suite has stopped. The host page's "Security repository" row shows the suite and its age. Set security_repo_stale_after_days = 0 to turn this off, e.g. for a local mirror that renames the suite. Agents before 0.9.0 don't report it.
  • 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 success stamps, update-success-stamp (Ubuntu, and kernelwatch-apt-update.service) and update-stamp (apt-daily), both in /var/lib/apt/periodic/ and touched only when apt update succeeds. A host with neither falls back to /var/lib/apt/lists/partial, which changes on failed updates too. The agent doesn't run apt update itself; it relies on apt-daily.timer or --with-apt-update. If the lists stop refreshing, 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.