Flag a /boot too full for the next kernel and packages dpkg left unfinished
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

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>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-31 18:54:47 -04:00
1 parent 3e2f550414
commit 70272efed5
13 files changed
+173 -5

No files matched your search

+1 -1
View File
@@ -4,4 +4,4 @@ __version__ = "0.4.0"
# Version of agent/kernelwatch-agent shipped alongside this server; older agents
# are noted on the dashboard. tests/test_status.py checks the two stay in sync.
AGENT_VERSION = "0.5.0"
AGENT_VERSION = "0.6.0"
+5
View File
@@ -30,6 +30,9 @@ class Config:
# Package lists older than this make "no updates" untrustworthy.
apt_stale_after_hours: float = 48.0
report_retention_days: int = 30
# Less free space than this on /boot's filesystem puts a host in update: the next
# kernel (image plus initramfs, often over 100 MB) may not fit. 0 disables.
boot_min_free_mb: int = 200
# Where `scheduled-backup` (kernelwatch-backup.timer) writes dated copies of the
# database, and how many days of them it keeps; 0 keeps them all. It must stay
@@ -93,6 +96,8 @@ def load(path: str | None = None) -> Config:
raise SystemExit(f"{path}: ntfy_timeout_seconds must be positive and finite")
if cfg.report_min_interval_seconds < 0:
raise SystemExit(f"{path}: report_min_interval_seconds must be zero or positive")
if cfg.boot_min_free_mb < 0:
raise SystemExit(f"{path}: boot_min_free_mb must be zero or positive")
if cfg.backup_keep_days < 0:
raise SystemExit(f"{path}: backup_keep_days must be zero or positive")
if not cfg.backup_dir.startswith("/") or any(ord(c) < 32 or ord(c) == 127 for c in cfg.backup_dir):
+3
View File
@@ -42,6 +42,9 @@ FIELDS: dict[str, str] = {
"livepatch_fix_count": "int",
"apt_simulation_ok": "bool",
"apt_simulation_error": "str",
"boot_size_kb": "int",
"boot_free_kb": "int",
"dpkg_unfinished_packages": "strlist",
"apt_lists_age_seconds": "int",
"uptime_seconds": "int",
}
+21
View File
@@ -146,6 +146,17 @@ def livepatch_cover(report: dict[str, Any], now: float) -> tuple[bool, str | Non
return True, f"live-patched; kernel upgrade needed by {deadline}"
def boot_space_low(report: dict[str, Any], cfg: Config) -> str | None:
"""Why /boot may be too full for the next kernel, or None. Agents before 0.6.0
don't report it, and a host whose df failed sends null; both count as fine."""
free_kb = report.get("boot_free_kb")
if not cfg.boot_min_free_mb or free_kb is None or free_kb >= cfg.boot_min_free_mb * 1024:
return None
size_kb = report.get("boot_size_kb")
used = f", {100 - free_kb * 100 // size_kb}% used" if size_kb else ""
return f"/boot has {free_kb // 1024} MB free{used}; the next kernel may not fit"
def _kernel_only_reboot_file(report: dict[str, Any]) -> bool:
"""/run/reboot-required exists only because of kernel packages."""
pkgs = report.get("reboot_required_pkgs") or []
@@ -208,6 +219,16 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
if sec := report.get("security_count"):
status.raise_to("update", f"{sec} security update{'s' if sec != 1 else ''} pending")
# dpkg stopped part-way (usually a failed postinst, often from a full /boot), so
# whatever it was installing, maybe a kernel, isn't in place yet.
if unfinished := report.get("dpkg_unfinished_packages"):
n = len(unfinished)
more = f", +{n - 5} more" if n > 5 else ""
status.raise_to("update", f"{n} package{'s' if n != 1 else ''} not fully installed: "
f"{', '.join(unfinished[:5])}{more}; run dpkg --configure -a")
if low := boot_space_low(report, cfg):
status.raise_to("update", low)
if services := report.get("services_need_restart"):
shown = ", ".join(s.removesuffix(".service") for s in services[:5])
more = f", +{len(services) - 5} more" if len(services) > 5 else ""
+3
View File
@@ -508,6 +508,9 @@ class Handler(BaseHTTPRequestHandler):
field("Reboot-required packages", r.get("reboot_required_pkgs"), code=True),
field("Services needing restart", services_summary(r)[1]),
field("Sessions needing restart", r.get("sessions_need_restart")),
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"),
field("Unfinished dpkg packages", r.get("dpkg_unfinished_packages"), code=True),
field("Package lists age", duration(r.get("apt_lists_age_seconds"))
if r.get("apt_lists_age_seconds") is not None else None),
field("Uptime", duration(r.get("uptime_seconds")) if r.get("uptime_seconds") is not None else None),