#!/usr/bin/env bash # Install the failure notifier and hook every fleet user unit on this box. # services/althing-notify-failure/install.sh [--dry-run] # # Idempotent. Re-running adds hooks for units that appeared since last time. set -euo pipefail cd "$(dirname "$0")" DRY="${1:-}" UD="${HOME}/.config/systemd/user" BIN="${HOME}/.local/bin" # dbus.service is systemd's own plumbing, not a fleet service -- excluded. # althing-notify-failure@ is excluded because a notifier must never report # itself (see the template's comment). SKIP_RE='^(dbus|althing-notify-failure@).*' run() { if [ "$DRY" = "--dry-run" ]; then echo " would: $*"; else "$@"; fi; } echo "== installing the notifier ==" run install -Dm755 althing-notify-failure "${BIN}/althing-notify-failure" run install -Dm644 althing-notify-failure@.service "${UD}/althing-notify-failure@.service" echo "== hooking fleet user units ==" mapfile -t UNITS < <(systemctl --user list-units --type=service --state=running --no-pager \ | awk '{print $1}' | grep '\.service$' | grep -Ev "$SKIP_RE") for u in "${UNITS[@]}"; do d="${UD}/${u}.d" run mkdir -p "$d" run install -m644 onfailure-drop-in.conf "${d}/10-onfailure-althing.conf" echo " hooked ${u}" done run systemctl --user daemon-reload echo "== ${#UNITS[@]} unit(s) hooked =="