mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-10 04:36:40 +00:00
hostname(1) is not installed in every node image. In run 30830377785 the arch
drill printed
trigger_units.sh: line 22: hostname: command not found
starting svc-bkp-local-2-device.11.6.0.infinito.nexus.service on
so the node name came out empty on all three call sites. The cosmetic one is the
progress line; the damaging one is the journal dump path, which becomes
"${unit}..journal.txt" and is identical on every node. Four hosts writing the
same filename into the shared dumps directory means the artifact keeps whichever
one wrote last, and a unit failure gets investigated against another host's
journal.
uname is coreutils and present wherever the drill runs. Reading it once also
drops three subshells from the loop.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
34 lines
1.3 KiB
Bash
Executable File
34 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Runs in-node. Starts every installed systemd unit matching a pattern.
|
|
#
|
|
# Arguments:
|
|
# $1 PATTERN systemd unit glob (e.g. 'svc-bkp-volume-2-local*.service')
|
|
# $2 DUMPS directory the full journal of a failed unit is written to
|
|
#
|
|
# Exit codes: 0 all units completed, 1 a unit failed (journal dumped),
|
|
# 2 no unit matches the pattern (caller decides whether that is fatal). The
|
|
# `|| true` is load-bearing: list-unit-files exits 1 on an empty glob, and
|
|
# under pipefail that would kill the script before the exit-2 contract runs.
|
|
set -euo pipefail
|
|
|
|
PATTERN="${1:?usage: trigger_units.sh PATTERN DUMPS}"
|
|
DUMPS="${2:?usage: trigger_units.sh PATTERN DUMPS}"
|
|
|
|
units="$(systemctl list-unit-files "${PATTERN}" --no-legend | awk '{print $1}' || true)"
|
|
[ -n "${units}" ] || exit 2
|
|
|
|
NODE="$(uname -n)"
|
|
|
|
while read -r unit; do
|
|
[ -n "${unit}" ] || continue
|
|
echo " starting ${unit} on ${NODE}"
|
|
if ! systemctl start "${unit}"; then
|
|
mkdir -p "${DUMPS}"
|
|
dump="${DUMPS}/${unit}.${NODE}.journal.txt"
|
|
journalctl -u "${unit}" --no-pager -o short-iso >"${dump}" 2>/dev/null || true
|
|
echo "FAILURE: ${unit} did not complete on ${NODE}; full journal at ${dump}"
|
|
journalctl -u "${unit}" --no-pager -o cat -n 40 2>/dev/null || true
|
|
exit 1
|
|
fi
|
|
done <<<"${units}"
|