runner cleanup: detect a running build by its locks instead of pgrep -f #76

Merged
kevinheyer merged 1 commit from cleanup-locks into main 2026-11-25 10:29:11 +01:00
Member

Refs iac-core#36 (the issue stays open until verified on the runner).

iac-runner-cleanup asks the locks of the image build and the boot test instead of pgrep -f, so an ssh session with bootstrap-vz in its arguments no longer skips the cleanup. The lock files are opened read-only (no O_CREAT, protected_regular) and held until the cleanup ends, so no build starts in its middle.

Differences to the issue: the image build releases its lock after bootstrap-vz (the compressing afterwards is covered by the existing half hour limit); a hard-killed build-image.sh leaves its children without a lock for a moment.

Tested: shellcheck, tools/lint.sh, the script with stubbed findmnt/losetup/kpartx/docker and IAC_LOCK_DIR: runs without locks and with a process named bootstrap-vz, does nothing while the build lock or the boot-test lock is held.
Not tested: on the runner during a real build and boot test. After merging it must be installed there (install -m 0755 iac-runner-cleanup /usr/local/sbin/).

🤖 Generated with Claude Code

https://claude.ai/code/session_014Px55FVUdXiuWr642SZTHK

Refs iac-core#36 (the issue stays open until verified on the runner). `iac-runner-cleanup` asks the locks of the image build and the boot test instead of `pgrep -f`, so an ssh session with `bootstrap-vz` in its arguments no longer skips the cleanup. The lock files are opened read-only (no O_CREAT, protected_regular) and held until the cleanup ends, so no build starts in its middle. Differences to the issue: the image build releases its lock after bootstrap-vz (the compressing afterwards is covered by the existing half hour limit); a hard-killed build-image.sh leaves its children without a lock for a moment. Tested: shellcheck, `tools/lint.sh`, the script with stubbed findmnt/losetup/kpartx/docker and IAC_LOCK_DIR: runs without locks and with a process named bootstrap-vz, does nothing while the build lock or the boot-test lock is held. Not tested: on the runner during a real build and boot test. After merging it must be installed there (`install -m 0755 iac-runner-cleanup /usr/local/sbin/`). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_014Px55FVUdXiuWr642SZTHK
runner cleanup: detect a running build by its locks instead of pgrep -f
All checks were successful
/ lint (push) Successful in 22s
/ lint (pull_request) Successful in 17s
30d35054a4
pgrep -f matched every process with "bootstrap-vz" in its arguments, so
an ssh session with "ls /srv/bootstrap-vz" made the cleanup skip its
run. The image build (until bootstrap-vz is done) and the boot test hold
a flock for their whole run, and do not pass it on to qemu or bootstrap-vz,
so a leftover VM cannot block the cleanup. The cleanup opens the lock
files read-only (no O_CREAT: protected_regular) and keeps them until it
ends, so no build starts in the middle of it.

Tested: shellcheck and tools/lint.sh; the script with stubbed findmnt,
losetup, kpartx and docker and IAC_LOCK_DIR: no lock files and unheld
locks: runs; a process with bootstrap-vz, build-image.sh and boot-test.sh
in its arguments: runs (the old script stopped); a held image-build lock
or boot-test lock: does nothing. Not tested: on the runner during a real
build and boot test.
Sign in to join this conversation.
No description provided.