From 4454beadb0250d6d2882a90fb683092d15a1c0bf Mon Sep 17 00:00:00 2001 From: Garrett Allen <98648590+Gerrrt@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:36:57 +0000 Subject: [PATCH 1/2] feat(trinity): collect SMART from trinity's own disks trinity was the one Alloy host with a checkout that read no SMART. A new sensitive-profile timer runs collect-smart-state.sh as root daily at 08:30, through a new make target that skips the baseline table so the SmartDriveBadSectors join keeps one copy. The build runbook installs smartmontools. Co-Authored-By: Claude Opus 5.5 --- Makefile | 13 +++++ docs/changelog.md | 12 +++++ .../runbooks/build-the-sensitive-tier-host.md | 16 +++++- docs/runbooks/schedule-maintenance.md | 15 +++++- scripts/install-timers.sh | 8 ++- systemd/README.md | 1 + .../homelab-smart-state-sensitive.service | 53 +++++++++++++++++++ .../homelab-smart-state-sensitive.timer | 18 +++++++ 8 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 systemd/sensitive/homelab-smart-state-sensitive.service create mode 100644 systemd/sensitive/homelab-smart-state-sensitive.timer diff --git a/Makefile b/Makefile index 87302018..dd0d99f1 100644 --- a/Makefile +++ b/Makefile @@ -438,6 +438,19 @@ smart-state: ## Collect SMART health from THIS host's disks (needs root) and ren ./scripts/collect-smart-state.sh; \ fi +.PHONY: smart-state-sensitive +smart-state-sensitive: ## Collect SMART health from trinity's own disks (needs root), without the baselines + @# trinity's half of `smart-state`, run by homelab-smart-state-sensitive.timer. + @# The collector alone: the baseline table is rendered once, on the + @# monitoring host, and SmartDriveBadSectors joins it on(host, slot), so a + @# second copy from here would break the join for every drive. + @# + @# No SKIP for a missing smartctl or a missing root here, unlike + @# `smart-state`: this target exists for the timer, which runs as root, and + @# a host built without smartmontools should fail the job and page + @# ScheduledJobFailed rather than report a clean run that read nothing. + ./scripts/collect-smart-state.sh + .PHONY: gateway-state gateway-state: ## Collect the firewall's view of its uplinks, DDNS record and GUI certificate (#353, #604, #857) @# Two measurements per family: what pfSense reports, and whether traffic of diff --git a/docs/changelog.md b/docs/changelog.md index 36fa63ae..1d75941e 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -17,6 +17,18 @@ roadmap as it read that day, and the *Done* entries keep the shape they had there. `check_docs.py` does not check this file, for the reason its module docstring gives: it is a record, not a claim about now. +## 2026-11-21 + +- **`trinity` reads SMART from its own disks.** It was the one host with a + checkout and Alloy that collected none, so a failing NVMe under the password + vault, or a failing photo disk, would have shown first as I/O errors. A new + sensitive-profile timer, `homelab-smart-state-sensitive`, runs the existing + collector as root daily at 08:30. It goes through a new make target, + `smart-state-sensitive`, and not `smart-state`, so the baseline table that + `SmartDriveBadSectors` joins stays rendered on the monitoring host alone. + The build runbook's step 4 now installs `smartmontools`. Found by the trinity + audit of 2026-11-13, which the repo had neither recorded nor decided. + ## 2026-11-20 - **`trinity` subscribes to the UPS, and the shutdown window is widened to diff --git a/docs/runbooks/build-the-sensitive-tier-host.md b/docs/runbooks/build-the-sensitive-tier-host.md index f33f37cc..1a67fdcf 100644 --- a/docs/runbooks/build-the-sensitive-tier-host.md +++ b/docs/runbooks/build-the-sensitive-tier-host.md @@ -240,7 +240,7 @@ One block, pasted on `trinity`. It asks for your `sudo` password once: ```bash sudo apt-get update -sudo apt-get install -y ca-certificates curl git make age tpm2-tools +sudo apt-get install -y ca-certificates curl git make age tpm2-tools smartmontools sudo install -m 0755 -d /etc/apt/keyrings curl -fsSL https://download.docker.com/linux/ubuntu/gpg \ | sudo tee /etc/apt/keyrings/docker.asc > /dev/null @@ -691,6 +691,20 @@ both kinds here and checks `oracle`'s copies against their MANIFESTs the installer primes it too. `verify-backups-sensitive.prom` must read exit code `0`. +And `smart-state-sensitive`, daily at 08:30, which reads SMART from the NVMe +and the photo disk as root. It needs `smartmontools` from step 4. The +installer primes it, so read what it found straight away: + +```bash +cat /var/lib/node_exporter/textfile_collector/smart-state-sensitive.prom +grep -E '^homelab_smart_(devices|healthy)' /var/lib/node_exporter/textfile_collector/smart-state-trinity.prom +``` + +The job's exit code must be `0`, and `homelab_smart_healthy` must carry a row +for `nvme0n1` and one for the photo disk. A USB disk whose bridge does not +pass SMART through is left out with a warning in +`journalctl -u homelab-smart-state-sensitive`, not counted as healthy. + ## 13. Before the first real photo, document or vault item These five are the gate on the data, not on the containers, and each is diff --git a/docs/runbooks/schedule-maintenance.md b/docs/runbooks/schedule-maintenance.md index a1f07de1..709763b9 100644 --- a/docs/runbooks/schedule-maintenance.md +++ b/docs/runbooks/schedule-maintenance.md @@ -742,6 +742,7 @@ checkout ([#404](https://github.com/Gerrrt/HomeLab/issues/404) step 9): | `backup-library` | `make backup-library` | daily 05:15 | 2 days | | `converge-sensitive` | `make converge` with `STACK=sensitive` | hourly at :25 | 3 hours | | `verify-backups-sensitive` | `make verify-backups` with `STACK=sensitive` | daily 06:30 | 2 days | +| `smart-state-sensitive` | `make smart-state-sensitive`, as **root** | daily 08:30 | 2 days | | `household-copy` | **you**, `make household-copy DEST=…` | no timer | 90 days | | `household-proof` | **you** and the holder, `make household-proof CODE=…` | no timer | 1 year | @@ -766,6 +767,16 @@ MANIFEST. That is where `oracle`'s copies are verified, without a key on `oracle`. It stops nothing, and it shares the `backups` lock so a prune never deletes a set it is reading. +`smart-state-sensitive` is the monitoring host's local `smart-state` for +`trinity`'s own disks: the boot NVMe and the USB photo disk at `/srv/immich`. +It runs as root for the same reason, and writes `smart-state-trinity.prom`, +which `SmartStateStale` and the drive rules read like any other host's. It is +not `make smart-state`, because that target also renders the baseline table +that `SmartDriveBadSectors` joins `on(host, slot)`, and a second copy from +`trinity` would put two series on every key. `make smart-state-sensitive` runs +the collector alone, and has no `SKIP`: a `trinity` without `smartmontools` +fails the job and pages `ScheduledJobFailed`. + `converge-sensitive` is the monitoring host's `converge` for the tier ([#533](https://github.com/Gerrrt/HomeLab/issues/533)). It shares the `backups` lock too, so it never runs `make up` under a quiesced tier. **Before @@ -780,12 +791,12 @@ make install-timers PROFILE=sensitive ``` That writes a `homelab-jobs.prom` on `trinity` that declares only these -six. `household-copy` and `household-proof` are the household's copy +seven. `household-copy` and `household-proof` are the household's copy ([ADR-0073](../adr/0073-carry-the-household-copy-on-a-drive-the-holder-keeps.md), [`carry-the-household-copy.md`](carry-the-household-copy.md)). They have no timer, and `HouseholdCopyStale` reads them. The alert rules join on the job name alone, so a name may appear in only one table, and `--check` enforces that. The installer primes `backup-library`, -`converge-sensitive` and `verify-backups-sensitive`, which stop nothing, and not `backup-sensitive`, which stops the tier. `make check-timers` checks both +`converge-sensitive`, `verify-backups-sensitive` and `smart-state-sensitive`, which stop nothing, and not `backup-sensitive`, which stops the tier. `make check-timers` checks both profiles, and `make validate` on `trinity` fails until the backup and converge timers are installed. diff --git a/scripts/install-timers.sh b/scripts/install-timers.sh index 522d03a5..17f8c518 100755 --- a/scripts/install-timers.sh +++ b/scripts/install-timers.sh @@ -171,8 +171,10 @@ JOBS=( # what keeps the alert joins one-to-one across hosts, so it must not reuse a # name from JOBS — check 8 below asserts that. And the nightly re-verification # of both kinds of set, here and on oracle (#856): verify-backups-sensitive, -# two days for the same reason as the backups it re-reads. There is no -# age-key proof row here either (ADR-0120). +# two days for the same reason as the backups it re-reads. And the daily SMART +# read of trinity's own disks, smart-state-sensitive, two days like the +# estate's smart-state; its unit says why it is not `make smart-state`. There +# is no age-key proof row here either (ADR-0120). # # The units under systemd/sensitive/ carry @DEPLOY_ROOT@, @RUN_USER@, # @RUN_GROUP@ and @RUN_HOME@ rather than a name, because the build runbook @@ -184,6 +186,7 @@ SENSITIVE_JOBS=( "backup-library homelab-backup-library 172800 backup-library" "converge-sensitive homelab-converge-sensitive 10800 converge" "verify-backups-sensitive homelab-verify-backups-sensitive 172800 verify-backups" + "smart-state-sensitive homelab-smart-state-sensitive 172800 smart-state-sensitive" "household-copy - 7776000 household-copy" "household-proof - 31536000 household-proof" ) @@ -694,6 +697,7 @@ if [[ "${PROFILE}" == sensitive ]]; then info "backup-library was primed: it stops nothing, and oracle now holds a set" info "converge-sensitive was primed: it applied nothing if HOMELAB_CONVERGE_APPLY=0 was set first" info "verify-backups-sensitive was primed: it re-read every set here and asked oracle to hash its copies" + info "smart-state-sensitive was primed: smart-state-trinity.prom holds this host's disks" info "backup-sensitive was NOT primed: it stops the tier. Run it when you can watch:" info " sudo systemctl start homelab-backup-sensitive.service" exit 0 diff --git a/systemd/README.md b/systemd/README.md index b06447ec..c8648559 100644 --- a/systemd/README.md +++ b/systemd/README.md @@ -75,6 +75,7 @@ instead. | `homelab-backup-sensitive` | daily 04:30 | Quiesces the tier and archives its volumes | | `homelab-backup-library` | daily 05:15 | Archives Immich's library and copies it to `oracle` | | `homelab-verify-backups-sensitive` | daily 06:30 | Proves every volume and library set still decrypts, and `oracle`'s copies still hash to their MANIFESTs | +| `homelab-smart-state-sensitive` | daily 08:30 | Reads SMART from `trinity`'s NVMe and photo disk, as root | ## On agent hosts diff --git a/systemd/sensitive/homelab-smart-state-sensitive.service b/systemd/sensitive/homelab-smart-state-sensitive.service new file mode 100644 index 00000000..532c5a68 --- /dev/null +++ b/systemd/sensitive/homelab-smart-state-sensitive.service @@ -0,0 +1,53 @@ +# SMART health for trinity's own disks: the boot NVMe that holds the tier, and +# the USB disk at /srv/immich that holds the photographs (ADR-0064). +# +# The monitoring host's homelab-smart-state.service, run on the other host with +# a checkout, and that unit explains every directive below; this one states +# only what differs. Before it, trinity was the one Alloy host with a checkout +# that read no SMART at all: a failing NVMe under the password vault would have +# said so first as I/O errors. +# +# NOT `make smart-state`. That target also renders smart-baselines.prom, and +# SmartDriveBadSectors joins it `on(host, slot)` from the one copy the +# monitoring host serves (scripts/render-smart-baselines.sh). A second copy +# from here would put two series on every key and break the join for the whole +# estate. `make smart-state-sensitive` runs the collector alone. +# +# ROOT, for the estate unit's reason: smartctl's ATA and NVMe pass-through +# ioctls need raw device access, and no group substitutes. Nothing here runs as +# @RUN_USER@, so the unit reads that user's checkout and writes one directory. +# +# THE HOUSEHOLD DRIVE IS READ WHILE IT IS PLUGGED IN, and that is fine. It is +# attached here between copies (ADR-0073) and leaves with the holder; its +# series stop when it does, and no rule reads a drive's absence. +[Unit] +Description=HomeLab: collect SMART health for trinity's disks +Documentation=file://@DEPLOY_ROOT@/docs/runbooks/schedule-maintenance.md + +[Service] +Type=oneshot +User=root +Group=root +WorkingDirectory=@DEPLOY_ROOT@ +EnvironmentFile=-/etc/default/homelab-timers +ExecStart=@DEPLOY_ROOT@/scripts/run-scheduled.sh --job smart-state-sensitive -- /usr/bin/make -C @DEPLOY_ROOT@ smart-state-sensitive +TimeoutStartSec=300 +Restart=no +Nice=10 +NoNewPrivileges=true +RestrictSUIDSGID=true +LockPersonality=true +RestrictRealtime=true +PrivateTmp=true +ProtectHome=read-only +ProtectSystem=strict +ReadWritePaths=/var/lib/node_exporter/textfile_collector +ProtectKernelTunables=true +ProtectKernelModules=true +ProtectControlGroups=true +PrivateNetwork=true +StandardOutput=journal +StandardError=journal +SyslogIdentifier=homelab-smart-state-sensitive + +# No [Install] section: the timer enables this. diff --git a/systemd/sensitive/homelab-smart-state-sensitive.timer b/systemd/sensitive/homelab-smart-state-sensitive.timer new file mode 100644 index 00000000..b68d1580 --- /dev/null +++ b/systemd/sensitive/homelab-smart-state-sensitive.timer @@ -0,0 +1,18 @@ +[Unit] +Description=HomeLab: daily SMART collection on trinity +Documentation=file://@DEPLOY_ROOT@/docs/runbooks/schedule-maintenance.md + +[Timer] +Unit=homelab-smart-state-sensitive.service +# 08:30, the estate's SMART time, so "every host's SMART is from this morning" +# stays true. Clear of the night's backups and their verification, which are +# done by 06:30 and hold the `backups` lock this does not take. +OnCalendar=*-*-* 08:30:00 +RandomizedDelaySec=900 +# True: a missed morning is collected at the next boot, so a gap in the series +# means "stopped reporting" and not "was off at 08:30". +Persistent=true +AccuracySec=1m + +[Install] +WantedBy=timers.target From fb060956f6f37d1b58c85e7bb723317d0915d73c Mon Sep 17 00:00:00 2001 From: Garrett Allen <98648590+Gerrrt@users.noreply.github.com> Date: Sat, 21 Nov 2026 01:56:27 +0000 Subject: [PATCH 2/2] fix(trinity): give the SMART job a lock directory it can write ProtectSystem=strict leaves /run/lock read-only, and run-scheduled.sh opens its lock there before running anything, so every run would have failed. HOMELAB_LOCK_DIR points it at the textfile directory, the one writable path. Co-Authored-By: Claude Opus 5.5 --- systemd/sensitive/homelab-smart-state-sensitive.service | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/systemd/sensitive/homelab-smart-state-sensitive.service b/systemd/sensitive/homelab-smart-state-sensitive.service index 532c5a68..c147d436 100644 --- a/systemd/sensitive/homelab-smart-state-sensitive.service +++ b/systemd/sensitive/homelab-smart-state-sensitive.service @@ -17,6 +17,14 @@ # ioctls need raw device access, and no group substitutes. Nothing here runs as # @RUN_USER@, so the unit reads that user's checkout and writes one directory. # +# ITS LOCK LIVES IN THE TEXTFILE DIRECTORY. run-scheduled.sh opens +# ${HOMELAB_LOCK_DIR:-/run/lock}/homelab-.lock before it runs anything, and +# ProtectSystem=strict leaves every path read-only but /dev, /proc, /sys and +# the ReadWritePaths below, /run/lock included. This job shares no lock with +# any other, so its own lock file can sit in the one directory it may write; +# node_exporter reads only *.prom there. Narrower than opening /run/lock, which +# holds other programs' locks. +# # THE HOUSEHOLD DRIVE IS READ WHILE IT IS PLUGGED IN, and that is fine. It is # attached here between copies (ADR-0073) and leaves with the holder; its # series stop when it does, and no rule reads a drive's absence. @@ -30,6 +38,7 @@ User=root Group=root WorkingDirectory=@DEPLOY_ROOT@ EnvironmentFile=-/etc/default/homelab-timers +Environment=HOMELAB_LOCK_DIR=/var/lib/node_exporter/textfile_collector ExecStart=@DEPLOY_ROOT@/scripts/run-scheduled.sh --job smart-state-sensitive -- /usr/bin/make -C @DEPLOY_ROOT@ smart-state-sensitive TimeoutStartSec=300 Restart=no