Flag hosts where unattended-upgrades has stopped succeeding #27

Merged
patrick merged 3 commits from feat/unattended-upgrades into main 2026-11-01 00:28:50 +00:00
Owner

Problem

Most of the fleet relies on unattended-upgrades for security patches (Ubuntu Server enables it by default). When it breaks (a conffile prompt, a held package, a disabled timer), nothing showed until security updates piled up, and in a quiet week nothing piles up at all.

Changes

Agent (0.8.0) reports, read-only and without root:

  • unattended_upgrades: enabled (package installed and APT::Periodic::Unattended-Upgrade non-zero), disabled, or not-installed. A removed package's leftover config (dpkg state rc) counts as not installed.
  • unattended_upgrades_success_age_seconds: age of /var/lib/apt/periodic/upgrade-stamp, which apt.systemd.daily touches only when unattended-upgrade exits 0.
  • unattended_upgrades_run_age_seconds: age of unattended-upgrades-stamp, which unattended-upgrades writes whenever a run gets far enough, even if it then fails.
  • unattended_upgrades_kept_back: packages it won't upgrade, from /var/lib/unattended-upgrades/kept-back.

Server, for hosts with it enabled:

  • No success in unattended_upgrades_stale_after_days (new setting, default 3, 0 disables) puts the host in update. The reason says whether it's failing (it ran recently: check the log) or not running (check apt-daily-upgrade.timer), or has never succeeded.
  • Enabled but no run yet (freshly installed): a note.
  • Kept-back packages: a note.
  • The host page shows the state, both ages and the kept-back packages.
  • Hosts with it disabled or not installed, and agents before 0.8.0, are judged as before.

Docs: README status table, a section in docs/how-it-works.md, the setting in server.toml.example.

Notes

  • Assumes the stock apt-daily-upgrade.timer runs it. A host running unattended-upgrade from cron or Ansible won't update upgrade-stamp; set unattended_upgrades_stale_after_days = 0 there (documented).
  • Reading the actual error would mean reading the root-only /var/log/unattended-upgrades/, which needs another root helper unit; left out for now.

Testing

  • make test: 294 tests pass.
  • Agent: enabled (including intervals other than 1 and always), switched off, setting absent, removed-with-config-left (rc), not installed, kept-back parsing.
  • Server: healthy, at the limit, not running, running but failing, never succeeded, not run yet, disabled and not installed ignored, check disabled or raised, kept-back notes and truncation, config validation, host page.
  • shellcheck wasn't available locally; CI runs it.

Deploying

git pull on the server host and the workstation, reinstall the server, then ./agent/deploy.sh <hosts> -- --with-needrestart --with-apt-update (without sudo).

🤖 Generated with Claude Code

## Problem Most of the fleet relies on unattended-upgrades for security patches (Ubuntu Server enables it by default). When it breaks (a conffile prompt, a held package, a disabled timer), nothing showed until security updates piled up, and in a quiet week nothing piles up at all. ## Changes **Agent (0.8.0)** reports, read-only and without root: - `unattended_upgrades`: `enabled` (package installed and `APT::Periodic::Unattended-Upgrade` non-zero), `disabled`, or `not-installed`. A removed package's leftover config (dpkg state `rc`) counts as not installed. - `unattended_upgrades_success_age_seconds`: age of `/var/lib/apt/periodic/upgrade-stamp`, which `apt.systemd.daily` touches only when `unattended-upgrade` exits 0. - `unattended_upgrades_run_age_seconds`: age of `unattended-upgrades-stamp`, which unattended-upgrades writes whenever a run gets far enough, even if it then fails. - `unattended_upgrades_kept_back`: packages it won't upgrade, from `/var/lib/unattended-upgrades/kept-back`. **Server**, for hosts with it enabled: - No success in `unattended_upgrades_stale_after_days` (new setting, default 3, `0` disables) puts the host in `update`. The reason says whether it's **failing** (it ran recently: check the log) or **not running** (check `apt-daily-upgrade.timer`), or has **never succeeded**. - Enabled but no run yet (freshly installed): a note. - Kept-back packages: a note. - The host page shows the state, both ages and the kept-back packages. - Hosts with it disabled or not installed, and agents before 0.8.0, are judged as before. **Docs**: README status table, a section in `docs/how-it-works.md`, the setting in `server.toml.example`. ## Notes - Assumes the stock `apt-daily-upgrade.timer` runs it. A host running `unattended-upgrade` from cron or Ansible won't update `upgrade-stamp`; set `unattended_upgrades_stale_after_days = 0` there (documented). - Reading the actual error would mean reading the root-only `/var/log/unattended-upgrades/`, which needs another root helper unit; left out for now. ## Testing - `make test`: 294 tests pass. - Agent: enabled (including intervals other than `1` and `always`), switched off, setting absent, removed-with-config-left (`rc`), not installed, kept-back parsing. - Server: healthy, at the limit, not running, running but failing, never succeeded, not run yet, disabled and not installed ignored, check disabled or raised, kept-back notes and truncation, config validation, host page. - shellcheck wasn't available locally; CI runs it. ## Deploying `git pull` on the server host and the workstation, reinstall the server, then `./agent/deploy.sh <hosts> -- --with-needrestart --with-apt-update` (without sudo). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
patrick added 3 commits 2026-11-01 00:27:17 +00:00
The agent now sends whether unattended-upgrades is enabled (package
installed, not just its leftover config, and APT::Periodic::Unattended-
Upgrade set and non-zero), the age of apt.systemd.daily's upgrade-stamp
(touched only when unattended-upgrade exits 0), the age of
unattended-upgrade's own stamp (written whenever a run gets far enough,
even if it then fails) and the packages it keeps back. Nothing reads them
yet. Agent 0.8.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a host with unattended-upgrades enabled, no successful run in
unattended_upgrades_stale_after_days (default 3, 0 disables) puts it in
update. The reason says which way it broke: still running but failing
("last succeeded 5d ago and is failing (last ran 6h ago); check
/var/log/unattended-upgrades/"), not running at all ("is
apt-daily-upgrade.timer enabled?"), or never succeeded. A host where it
hasn't completed its first run yet gets a note, and packages it keeps back
are noted. Hosts with it disabled or not installed, and agents before
0.8.0, are judged as before. The host page shows the state, both stamp
ages and the kept-back packages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Document the unattended-upgrades check
CI / tests (Python 3.11) (pull_request) Successful in 31s
CI / tests (Python 3.10) (pull_request) Successful in 31s
CI / tests (Python 3.12) (pull_request) Successful in 31s
CI / tests (Python 3.13) (pull_request) Successful in 31s
CI / lint (pull_request) Successful in 3s
da84ec1625
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
patrick merged commit 4f45187ca0 into main 2026-11-01 00:28:50 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: patrick/kernel-automation#27