Add daily 03:30 export schedule (systemd timer)
This host has no cron daemon (it is systemd-based), so schedule export-runner.sh via a
systemd timer rather than cron. cron-export.sh wraps the run with a sane PATH, flock
serialisation (no overlapping runs), and per-run logs under runtime/logs/. The timer is
Persistent, so a 03:30 run missed because the machine was asleep/off is caught up on the
next boot -- which plain cron does not do.
- scripts/cron-export.sh: scheduled-run wrapper.
- deploy/systemd/ctrader-export.{service,timer}: the units (install: sudo cp into
/etc/systemd/system/ then enable -- see deploy/systemd/README.md).
This commit is contained in:
Executable
+29
@@ -0,0 +1,29 @@
|
||||
#!/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
|
||||
Reference in New Issue
Block a user