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

+26 -1
View File
@@ -6,7 +6,7 @@
# rules can change without redeploying agents.
set -euo pipefail
AGENT_VERSION=0.5.0
AGENT_VERSION=0.6.0
# Prefix for every file the agent reads. Only the test suite sets this.
ROOT=${KERNELWATCH_ROOT:-}
@@ -242,6 +242,25 @@ apt_lists_age() {
return 0
}
# 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
# mount. A full /boot makes the next kernel's postinst fail, so the host stays
# on its old kernel with apt half-done.
boot_space() {
df -Pk "$ROOT/boot" 2>/dev/null |
awk 'NR == 2 && $2 ~ /^[0-9]+$/ && $4 ~ /^[0-9]+$/ { print $2, $4 }' || true
}
# Packages dpkg didn't finish installing or removing: half-installed, unpacked,
# half-configured, awaiting or pending triggers, or flagged reinst-required.
# The same states `dpkg --audit` reports; usually a failed postinst, cleared by
# `dpkg --configure -a`. Reads the status database only.
unfinished_packages() {
dpkg-query -W -f='${db:Status-Abbrev}\t${binary:Package}\n' 2>/dev/null |
awk -F '\t' 'substr($1, 2, 1) ~ /[HUFWt]/ || substr($1, 3, 1) == "R" { print $2 }' |
sort -u || true
}
uptime_seconds() {
local up _
[[ -r $ROOT/proc/uptime ]] || return 0
@@ -251,6 +270,7 @@ uptime_seconds() {
build_report() {
local running newest kernels sim inst sim_err rc apt_ok=1 apt_err='' reboot_file=0 reboot_pkgs=
local boot_size='' boot_free=''
running=$(uname -r)
kernels=$(installed_kernels)
@@ -274,6 +294,8 @@ build_report() {
[[ -r $ROOT/run/reboot-required.pkgs ]] && reboot_pkgs=$(sort -u "$ROOT/run/reboot-required.pkgs")
fi
read -r boot_size boot_free <<<"$(boot_space)" || true
printf '{'
printf '"agent_version":%s,' "$(json_str "$AGENT_VERSION")"
printf '"reported_hostname":%s,' "$(json_str "${REPORT_HOSTNAME:-$(hostname -f 2>/dev/null || hostname)}")"
@@ -310,6 +332,9 @@ build_report() {
printf '"livepatch_supported":%s,' "$(json_str_or_null "$LP_SUPPORTED")"
printf '"livepatch_upgrade_required":%s,' "$(json_str_or_null "$LP_UPGRADE")"
printf '"livepatch_fix_count":%s,' "$(json_int "$LP_FIXES")"
printf '"boot_size_kb":%s,' "$(json_int "$boot_size")"
printf '"boot_free_kb":%s,' "$(json_int "$boot_free")"
printf '"dpkg_unfinished_packages":%s,' "$(unfinished_packages | json_str_array)"
printf '"apt_lists_age_seconds":%s,' "$(json_int "$(apt_lists_age)")"
printf '"uptime_seconds":%s' "$(json_int "$(uptime_seconds)")"
printf '}\n'