Files
kernel-automation/agent/kernelwatch-apt-update.service
patrickandClaude Opus 5.5 f314fa331e
CI / tests (Python 3.10) (pull_request) Successful in 43s
CI / tests (Python 3.11) (pull_request) Successful in 43s
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
Stop kernelwatch-apt-update starving for disk on busy hosts
On nike (I/O pressure "full" around 86%), kernelwatch-apt-update.service
timed out after 5 minutes every run. The downloads were quick, but apt
then spent the rest of the time reading and writing its lists. At normal
priority the same apt-get update took 1m31s.

The unit ran in the idle I/O class, which gets disk time only when
nothing else wants it, so under constant I/O apt got almost none. It now
uses the lowest best-effort priority (IOSchedulingPriority=7). That still
yields to everything else on the host, but apt can't be starved.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 15:46:44 -05:00

58 lines
2.4 KiB
Desktop File

[Unit]
Description=Refresh apt package lists (for kernelwatch)
# Pulled in by kernelwatch-agent.service before each report, so updates show up
# within the hour instead of whenever apt-daily next refreshes the lists (on
# Debian, by default, never). Enabled by `install.sh --with-apt-update`.
ConditionPathExists=/etc/kernelwatch/apt-update
Wants=network-online.target
After=network-online.target
[Service]
Type=oneshot
# Same as `apt-get update`: downloads lists, installs nothing. A failure (no
# network, lock held by an admin's apt run) fails this unit but not the report,
# since kernelwatch-agent.service only Wants= it. The stamp then stops moving
# and the dashboard flags the lists as old.
ExecStart=/usr/bin/apt-get -q update
# Reached only when apt succeeded. It's the stamp Ubuntu's update-notifier hook
# writes after every successful apt update, and the agent reads it as the lists'
# age; Debian has nothing else that writes it. lists/partial, the agent's last
# resort, changes even when the update fails.
ExecStartPost=/bin/sh -c 'mkdir -p /var/lib/apt/periodic && touch /var/lib/apt/periodic/update-success-stamp'
# Records how the run ended, success or not, so the agent can report failures,
# which are otherwise silent while apt-daily keeps the lists fresh.
ExecStopPost=/usr/local/sbin/kernelwatch-unit-result apt-update
RuntimeDirectory=kernelwatch
RuntimeDirectoryMode=0755
RuntimeDirectoryPreserve=yes
UMask=0022
TimeoutStartSec=5min
# Lowest best-effort disk priority, not the idle class: idle gets disk time only
# when nothing else wants it, so on a host with constant I/O apt waits on
# reading and writing its lists until the timeout kills it, every run.
Nice=10
IOSchedulingClass=best-effort
IOSchedulingPriority=7
# apt needs root to write /var/lib/apt and drops to _apt for downloads, so this
# runs as root (the default) but loses everything apt update doesn't touch.
# Don't add User=root: with it, NoNewPrivileges and any of the seccomp-based
# options below, apt 2.7+ (Ubuntu 24.04, Debian 13) can't switch to _apt
# ("seteuid 42 failed - seteuid (1: Operation not permitted)") and every update
# fails.
NoNewPrivileges=yes
ProtectHome=yes
PrivateTmp=yes
PrivateDevices=yes
ProtectKernelTunables=yes
ProtectKernelModules=yes
ProtectKernelLogs=yes
ProtectControlGroups=yes
ProtectClock=yes
ProtectHostname=yes
RestrictNamespaces=yes
RestrictRealtime=yes
LockPersonality=yes
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6 AF_NETLINK
SystemCallArchitectures=native