Report packages on hold, and flag held kernel packages

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>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-11-01 15:24:27 -05:00
1 parent f88261d2f5
commit 4676942108
7 files changed
+61 -1

No files matched your search

+10
View File
@@ -308,6 +308,15 @@ security_repo() {
return 0 return 0
} }
# Installed packages on hold (`apt-mark hold`, or dpkg's "hold" selection). apt
# never upgrades them and the simulation doesn't list them, so their updates,
# security ones included, don't show up anywhere else.
held_packages() {
dpkg-query -W -f='${db:Status-Abbrev}\t${binary:Package}\n' 2>/dev/null |
awk -F '\t' 'substr($1, 1, 2) == "hi" { print $2 }' |
sort -u || true
}
# Size and free space of the filesystem holding /boot, in KiB, as "SIZE FREE"; # Size and free space of the filesystem holding /boot, in KiB, as "SIZE FREE";
# empty if df can't tell. That's the root filesystem when /boot isn't its own # empty if df can't tell. That's the root filesystem when /boot isn't its own
# mount. A full /boot makes the next kernel's postinst fail, so the host stays # mount. A full /boot makes the next kernel's postinst fail, so the host stays
@@ -456,6 +465,7 @@ build_report() {
printf '"boot_size_kb":%s,' "$(json_int "$boot_size")" printf '"boot_size_kb":%s,' "$(json_int "$boot_size")"
printf '"boot_free_kb":%s,' "$(json_int "$boot_free")" printf '"boot_free_kb":%s,' "$(json_int "$boot_free")"
printf '"dpkg_unfinished_packages":%s,' "$(unfinished_packages | json_str_array)" printf '"dpkg_unfinished_packages":%s,' "$(unfinished_packages | json_str_array)"
printf '"held_packages":%s,' "$(held_packages | json_str_array)"
case $pro_attached in case $pro_attached in
true | false) printf '"ubuntu_pro_attached":%s,' "$pro_attached" ;; true | false) printf '"ubuntu_pro_attached":%s,' "$pro_attached" ;;
*) printf '"ubuntu_pro_attached":null,' ;; *) printf '"ubuntu_pro_attached":null,' ;;
+10 -1
View File
@@ -10,7 +10,7 @@ Each host gets one status. When several apply, the worst one wins:
|----------|---------| |----------|---------|
| `stale` | No report in `stale_after_hours` (default 3h), or never. Other data can't be trusted. | | `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. | | `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, dpkg left packages half-installed, 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. | | `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, 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. | | `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 Each row also lists the reasons behind its status, and clicking a host shows
@@ -106,6 +106,15 @@ How the agent works it out:
host: `sudo dpkg --configure -a` (after freeing space, if that was the cause). 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 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. 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 - **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 never offers one again, so the host would show `ok` indefinitely. The server
knows when each supported release's free security support ends knows when each supported release's free security support ends
+1
View File
@@ -45,6 +45,7 @@ FIELDS: dict[str, str] = {
"boot_size_kb": "int", "boot_size_kb": "int",
"boot_free_kb": "int", "boot_free_kb": "int",
"dpkg_unfinished_packages": "strlist", "dpkg_unfinished_packages": "strlist",
"held_packages": "strlist",
"ubuntu_pro_attached": "bool", "ubuntu_pro_attached": "bool",
"ubuntu_esm_infra": "str", "ubuntu_esm_infra": "str",
"unattended_upgrades": "str", "unattended_upgrades": "str",
+15
View File
@@ -327,6 +327,21 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
more = f", +{n - 5} more" if n > 5 else "" more = f", +{n - 5} more" if n > 5 else ""
status.raise_to("update", f"{n} package{'s' if n != 1 else ''} not fully installed: " status.raise_to("update", f"{n} package{'s' if n != 1 else ''} not fully installed: "
f"{', '.join(unfinished[:5])}{more}; run dpkg --configure -a") f"{', '.join(unfinished[:5])}{more}; run dpkg --configure -a")
# Held packages never upgrade, and the simulation doesn't list them, so a held
# kernel package would make a host look current forever. Other holds are
# usually deliberate, but their updates (security ones too) are invisible.
if held := report.get("held_packages"):
kernel = [p for p in held if p.startswith("linux-")]
other = [p for p in held if not p.startswith("linux-")]
if kernel:
status.raise_to("update", f"kernel package{'s' if len(kernel) != 1 else ''} on hold, so "
f"kernel updates won't install: {', '.join(kernel[:5])}"
f"{', …' if len(kernel) > 5 else ''}; apt-mark unhold to release")
if other:
more = f", +{len(other) - 5} more" if len(other) > 5 else ""
status.note(f"{len(other)} package{'s' if len(other) != 1 else ''} on hold, "
f"updates to {'them' if len(other) != 1 else 'it'} won't show: "
f"{', '.join(other[:5])}{more}")
if low := boot_space_low(report, cfg): if low := boot_space_low(report, cfg):
status.raise_to("update", low) status.raise_to("update", low)
+1
View File
@@ -547,6 +547,7 @@ class Handler(BaseHTTPRequestHandler):
field("/boot free", None if r.get("boot_free_kb") is None else field("/boot free", None if r.get("boot_free_kb") is None else
f"{r['boot_free_kb'] // 1024} MB of {(r.get('boot_size_kb') or 0) // 1024} MB"), f"{r['boot_free_kb'] // 1024} MB of {(r.get('boot_size_kb') or 0) // 1024} MB"),
field("Unfinished dpkg packages", r.get("dpkg_unfinished_packages"), code=True), field("Unfinished dpkg packages", r.get("dpkg_unfinished_packages"), code=True),
field("Packages on hold", r.get("held_packages"), code=True),
field("unattended-upgrades", unattended_upgrades_summary(r)), field("unattended-upgrades", unattended_upgrades_summary(r)),
field("Kept back by unattended-upgrades", r.get("unattended_upgrades_kept_back"), code=True), field("Kept back by unattended-upgrades", r.get("unattended_upgrades_kept_back"), code=True),
field("Package lists age", duration(r.get("apt_lists_age_seconds")) field("Package lists age", duration(r.get("apt_lists_age_seconds"))
+12
View File
@@ -172,6 +172,18 @@ class AgentReportTest(AgentCase):
"libbar2", "libfoo1:amd64", "linux-headers-6.12.60+deb13-amd64", "libbar2", "libfoo1:amd64", "linux-headers-6.12.60+deb13-amd64",
"linux-image-6.12.60+deb13-amd64", "man-db"]) "linux-image-6.12.60+deb13-amd64", "man-db"])
def test_held_packages(self):
with open(os.path.join(self.root, "dpkg-all"), "w") as f:
f.write("ii \tcurl\n"
"hi \tlinux-image-amd64\n"
"hi \tpostgresql-16\n"
"hn \tnot-installed\n"
"hc \tremoved-but-held\n"
"iF \tbroken\n")
r = self.report()
self.assertEqual(r["held_packages"], ["linux-image-amd64", "postgresql-16"])
self.assertEqual(r["dpkg_unfinished_packages"], ["broken"])
def test_no_unfinished_packages(self): def test_no_unfinished_packages(self):
with open(os.path.join(self.root, "dpkg-all"), "w") as f: with open(os.path.join(self.root, "dpkg-all"), "w") as f:
f.write("ii \tcurl\nrc \told-pkg\n") f.write("ii \tcurl\nrc \told-pkg\n")
+12
View File
@@ -339,6 +339,18 @@ class EvaluateTest(unittest.TestCase):
self.assertEqual(self.level(report(dpkg_unfinished_packages=[])).level, "ok") self.assertEqual(self.level(report(dpkg_unfinished_packages=[])).level, "ok")
self.assertEqual(self.level(report(dpkg_unfinished_packages=None)).level, "ok") self.assertEqual(self.level(report(dpkg_unfinished_packages=None)).level, "ok")
def test_held_kernel_package_is_a_problem(self):
s = self.level(report(held_packages=["linux-image-amd64"]))
self.assertEqual(s.level, "update")
self.assertEqual(s.reasons, ["kernel package on hold, so kernel updates won't install: "
"linux-image-amd64; apt-mark unhold to release"])
def test_other_held_packages_are_a_note(self):
s = self.level(report(held_packages=["postgresql-16", "docker-ce"]))
self.assertEqual(s.level, "ok")
self.assertEqual(s.reasons, ["2 packages on hold, updates to them won't show: postgresql-16, docker-ce"])
self.assertEqual(self.level(report(held_packages=[])).reasons, [])
def test_os_past_end_of_support(self): def test_os_past_end_of_support(self):
s = self.level(report(os_id="debian", os_version_id="11")) s = self.level(report(os_id="debian", os_version_id="11"))
self.assertEqual(s.level, "update") self.assertEqual(s.level, "update")