Skip to content

feat(range): build gandalf's power-off timer (ADR-0124) - #1649

Merged
Gerrrt merged 6 commits into
gerrrt/gandalf-poweroff-timer-adrfrom
gerrrt/gandalf-poweroff-timer
Nov 23, 2026
Merged

Gerrrt merged 6 commits into
gerrrt/gandalf-poweroff-timer-adrfrom
gerrrt/gandalf-poweroff-timer

Conversation

@Gerrrt

@Gerrrt Gerrrt commented Nov 23, 2026

Copy link
Copy Markdown
Owner

What changed

Builds ADR-0124 in the repository. Nothing is installed on gandalf yet.

  • scripts/range-poweroff.sh (as /usr/local/sbin/homelab-range-poweroff):
    • check warns or powers off;
    • status prints the deadline and the time left;
    • extend H sets the deadline H hours from now, 1 to 12. The same script linked as range-extend does this too.
    • The deadline lives under /run, so every boot starts the six hours again. It defaults to six hours after boot.
    • wall warns at 30 and 5 minutes. Each warning is recorded against its deadline, so an extension re-arms both.
    • Past the deadline, it waits while dpkg holds its lock, then runs systemctl poweroff. Proxmox's own stopall stops the guests.
  • systemd/range/: a oneshot service with a hardened sandbox, and a timer every 5 minutes from 5 minutes after boot. systemd/README.md gains the directory (now five), and scripts/README.md the row.
  • build-the-playground.md §7:
    • The power-off timer: install from Hicks, how to run it, and a one-off proof.
    • The read-back now checks the timer is enabled and active.
    • The install runs range-extend 6 before enabling. Otherwise, on a box already up six hours, the first run would power it off five minutes after the install.
  • Changelog and roadmap: an entry for the build. Power gandalf off on a timer (ADR-0124) #1647 stays open until the proof on the box.

Stacked on #1648, which is stacked on #1646. Merge those first.

Why

Two audits found gandalf left on for days. ADR-0124 chose a timer on the host as the backstop. This is that timer. Refs #1647.

Blast radius

gandalf only, once installed. What goes wrong if this is wrong:

  • It powers off when it shouldn't. The guests stop through Proxmox's shutdown, and the session is lost. The targets revert at the next start anyway.
  • It doesn't power off. That is no worse than today.

The dpkg wait has no cap. A hung dpkg would hold the box on until someone looks, and that was chosen over cutting a package install half way. A session driven only from the 8006 web UI sees no wall warning, and §7 says so.

  • No change to network segmentation or firewall rules
  • No new port published to a VLAN that could not already reach the service
  • No credential added outside secrets/*.sops.yaml

Verification

  • ./scripts/range-poweroff.sh --self-test: 18/18 PASS (bash 5.3, macOS). The fixtures cover:
    • no warning on a fresh boot;
    • each warning sent once;
    • the power-off at the deadline;
    • the dpkg wait, then the power-off once dpkg is done;
    • an extension moving and re-arming the deadline;
    • extend refusing 0, 13, 2h and nothing;
    • 08 read as eight, not octal;
    • a corrupt state file falling back to boot + 6 h.
  • Mutation check. Removing the dpkg wait, the 12-hour cap, or the 5-minute warning each failed 1 or 2 fixtures. An unchanged copy failed none.
  • The same self-test on gandalf, piped to bash -s with nothing installed: 18 PASS.
  • systemd-analyze verify on gandalf (units in a temp dir, removed after): the only error is that /usr/local/sbin/homelab-range-poweroff doesn't exist yet. systemd-analyze security rates the service 7.0 MEDIUM, as expected for a root unit that must call poweroff and wall.
  • self-tests.sh discovers the suite. Locally, 14 other suites fail on this Mac (no docker, BSD tools). The same 14 fail on a clean origin/main worktree, and the diff between the two runs is only + PASS range-poweroff.sh --self-test (18 fixtures).
  • Other checks: check_docs.py OK. Pinned markdownlint-cli2 0.24.1: 0 issues. shellcheck: clean. lint.sh: ruff, yamllint, shellcheck and actionlint pass. ansible-lint FAILED on the same local runner error as docs(range): write gandalf's 2026-11-22 audit fixes into the runbook #1646, and docker-only checks were skipped.
  • make validate passes. It was not run, because there is no docker daemon here.
  • Deployed to the lab and confirmed working. Not yet: §7's install and one-power-off proof are next.
  • Docs updated

🤖 Generated with Claude Code

scripts/range-poweroff.sh powers gandalf off six hours after boot or after
the last range-extend (1 to 12 hours). It warns every shell at 30 and 5
minutes, and waits while dpkg holds its lock. systemd/range/ runs it every
five minutes. build-the-playground.md section 7 installs it from Hicks
(range-extend 6 first, so an install on a long-up box doesn't power it off
at once), and the read-back checks the timer is enabled and active.

Its 18-fixture --self-test is discovered by self-tests.sh. It passed locally
and under gandalf's bash, and each of three deliberate breaks failed it.
Not installed on gandalf yet.

Refs #1647.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 23, 2026 01:40
…poweroff-timer

# Conflicts:
#	docs/runbooks/build-the-playground.md
@Gerrrt
Gerrrt added this pull request to stack #1650 November 23, 2026 01:42
Installed 2026-11-22 17:44 from this branch by section 7's commands. The
self-test passed, the deadline was 23:44, a run by hand succeeded, and the
timer is enabled and active. The one-power-off proof is not yet run.

Refs #1647.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unlocked deadline operations can trigger shutdown after a successful extension or mishandle concurrent updates, while the timer cadence can skip the five-minute warning.

2 open issues
What changed in this PR

Implements ADR-0124’s automatic power-off backstop for gandalf, the range host. Deployment and the live warning, extension, and shutdown proof remain pending under #1647.

Changes:

  • Adds deadline checks, shell warnings, bounded extensions, and shutdown deferral while package installation is busy.
  • Adds a hardened systemd service and five-minute timer.
  • Documents installation and verification, adds deadline-logic fixtures, and records implementation progress.
File Description
systemd/​README.md Documents the new range unit directory.
systemd/​range/​homelab-range-poweroff.timer Schedules periodic deadline checks.
systemd/​range/​homelab-range-poweroff.service Runs the shutdown check with sandboxing.
scripts/​self-tests.sh Adds a comment describing the range fixtures.
scripts/​README.md Documents the power-off script and its purpose.
scripts/​range-poweroff.sh Implements deadline management, warnings, shutdown, and fixtures.
docs/​runbooks/​build-the-playground.md Adds installation, read-back, and live-proof steps.
docs/​roadmap.md Updates implementation and deployment tracking.
docs/​changelog.md Records the build and pending host deployment.

Review effort: Balanced

Comment thread scripts/range-poweroff.sh Resolved
Gerrrt added a commit that referenced this pull request Nov 23, 2026
Review on #1649: a five-minute cadence equals the five-minute warning
window, so a late run could skip the last warning. And without a lock, a
check could act on a deadline an extension had just replaced. The decision
now says every minute and one lock, and the Consequence's lag is about a
minute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Gerrrt and others added 2 commits November 22, 2026 17:47
…minute

Review on #1649 caught two problems:
- Without a lock, a check that had read the old deadline could power off
  after range-extend reported success, and two extensions shared one
  temporary file. check and extend now hold one flock for the whole
  operation, and the temporary file is unique.
- A five-minute timer equals the five-minute warning window, so a late run
  could skip the last warning. The timer now runs every minute with
  AccuracySec=5s.

Two fixtures prove the lock's interleavings. They skip where there is no
flock (macOS) and both fail with the lock removed. The self-test has 21
fixtures and passed under gandalf's bash. Reinstalled on gandalf.

Refs #1647.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Gerrrt
Gerrrt merged commit 87dab73 into main Nov 23, 2026
9 checks passed
@Gerrrt
Gerrrt deleted the gerrrt/gandalf-poweroff-timer branch November 23, 2026 03:09
Gerrrt added a commit that referenced this pull request Nov 23, 2026
* docs(range): write gandalf's 2026-11-22 audit fixes into the runbook

The second read-only audit found containment holding and four gaps.
build-the-playground.md gains:
- section 2: ip-forward off on vmbr0, and a netdev ingress table on vmbr1
  so the host takes nothing from the range, ARP included;
- section 4: X11 and TCP forwarding off in the keys-only drop-in, and
  "Nothing else on gandalf", which removes the dotfiles install and the
  third-party apt repos;
- section 7: a read-back for each;
- section 8: check four proves the ingress table, and the stale
  "until 902 is rebuilt" note is updated.

security.md gains the row. The changelog records the audit, including the
credential cleanup nothing had recorded. None of it is applied on gandalf
yet.

Refs #421.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(adr): ADR-0124, power gandalf off on a timer

Two audits found the range host left on for days, against the "off
between sessions" that ADR-0017's "no monitoring" rests on. ADR-0124
chooses a timer on the host over a collector and an "on too long" alert.
The host powers off six hours after boot or after the last range-extend
(capped at twelve hours), warns 30 and 5 minutes before, and waits while
dpkg holds its lock.

ADR-0017 gains a note. build-the-playground.md section 7 says the timer is
decided and not built. The changelog and roadmap gain entries, and README's
ADR count is 124. #1647 builds it.

Refs #1647.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(adr): ADR-0124's six hours is the default deadline, not the bound

range-extend replaces the deadline with 1 to 12 hours from now, and the
power-off can lag the deadline by a timer period and by a held dpkg lock.
The decision and the first Consequence now say so, and the ADR-0017 note,
the changelog entry and section 7 match.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs(adr): ADR-0124's check runs every minute, under one lock

Review on #1649: a five-minute cadence equals the five-minute warning
window, so a late run could skip the last warning. And without a lock, a
check could act on a deadline an extension had just replaced. The decision
now says every minute and one lock, and the Consequence's lag is about a
minute.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants