#!/usr/bin/env bash # # Wrapper for scheduled (systemd timer) runs of export-runner.sh. # Sets a sane PATH (schedulers run with a minimal environment), serialises runs with # flock so a slow run never overlaps the next tick, and logs each run under # runtime/logs/ (gitignored). set -uo pipefail export PATH="/usr/local/bin:/usr/bin:/bin" REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" LOG_DIR="$REPO_ROOT/runtime/logs" mkdir -p "$LOG_DIR" LOG="$LOG_DIR/export-$(date +%Y%m%d-%H%M%S).log" # Serialise: if a previous run is still going, skip this tick instead of piling up. exec 9>"$LOG_DIR/.lock" if ! flock -n 9; then echo "$(date): another export run is still in progress — skipping this tick" >> "$LOG" exit 0 fi { echo "=== scheduled export run: $(date) ===" "$REPO_ROOT/scripts/export-runner.sh" echo "=== exit $? at $(date) ===" } >> "$LOG" 2>&1 # Keep the log dir tidy: drop runs older than 30 days. find "$LOG_DIR" -name 'export-*.log' -mtime +30 -delete 2>/dev/null || true