#!/usr/bin/env bash # Runs as ExecStartPre of cc-ci-loops.service. Appends ONE line to REBOOTS.md per genuine reboot. # Uses the kernel boot_id to distinguish a real reboot from a mere `systemctl restart` of the unit: # only logs when the current boot_id differs from the last one we recorded. set -u REBOOTS="/srv/cc-ci/cc-ci-plan/REBOOTS.md" LAST_BOOT_FILE="/srv/cc-ci/.cc-ci-logs/.last-boot-id" PHASE_IDX_FILE="/srv/cc-ci/.cc-ci-logs/.phase-idx" cur_boot="$(cat /proc/sys/kernel/random/boot_id 2>/dev/null || echo unknown)" last_boot="$(cat "$LAST_BOOT_FILE" 2>/dev/null || echo '')" # Same boot_id => this is a manual service restart, not a reboot => do nothing. [ "$cur_boot" = "$last_boot" ] && exit 0 idx="$(cat "$PHASE_IDX_FILE" 2>/dev/null || echo '?')" ts="$(date '+%Y-%m-%d %H:%M:%S %Z')" mkdir -p "$(dirname "$LAST_BOOT_FILE")" printf '%s\n' "- $ts — reboot detected; loops auto-started by systemd (resuming phase index $idx). boot_id=$cur_boot" >> "$REBOOTS" 2>/dev/null || true echo "$cur_boot" > "$LAST_BOOT_FILE" 2>/dev/null || true exit 0