Eight cron monitors, two per game, watched eight scripts that run on the same box at the same two minutes. hall-nightly.sh now runs the hall's own rollup and every game's rollup at 00:12, and every game's backup at 07:23, finding the games by their scripts in /usr/local/bin, and checks in once for each job to the gamehall project's hall-rollup and hall-backup monitors. The template's rollup and backup say by their exit status whether they managed, the skipped backup included, and its deploy leaves the game's own cron file off a host the hall schedules. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
31 lines
1.5 KiB
Bash
Executable File
31 lines
1.5 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Nightly rollup: one JSON line per day in /var/lib/gamehall/rollup.jsonl,
|
|
# the hall's counts for that day (people, views, bots, referrers, campaigns,
|
|
# and the people sent on to each game here). Counts only: no addresses are
|
|
# kept, so the trend outlives the self-rotating access log.
|
|
# gamehall-rollup.sh [YYYY-MM-DD] (default: yesterday, UTC)
|
|
# Run nightly by hall-nightly.sh rollup (/etc/cron.d/gamehall).
|
|
set -u
|
|
OUT="/var/lib/gamehall/rollup.jsonl"
|
|
LOG="/var/log/gamehall/rollup.log"
|
|
DAY="${1:-$(date -u -d 'yesterday' +%Y-%m-%d)}"
|
|
mkdir -p "$(dirname "$OUT")" "$(dirname "$LOG")"
|
|
python3 - "$DAY" "$OUT" <<'PY' >> "$LOG" 2>&1
|
|
import datetime, json, os, sys
|
|
sys.path.insert(0, "/usr/local/lib/gamehall")
|
|
import traffic
|
|
day, out = sys.argv[1], sys.argv[2]
|
|
t = traffic.scan(day)
|
|
row = dict(day=day, people=len(t["addresses"]), views=t["views"], botAddresses=len(t["botAddresses"]),
|
|
scanners=t["scanners"], monitors=t["monitors"], sharedOn=dict(t["shared"]),
|
|
referrers=dict(t["referrers"]), campaigns=dict(t["campaigns"]), sent=t["sent"],
|
|
at=datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="seconds"))
|
|
rows = [json.loads(l) for l in open(out) if l.strip()] if os.path.exists(out) else []
|
|
rows = sorted([r for r in rows if r.get("day") != day] + [row], key=lambda r: r["day"])
|
|
with open(out + ".tmp", "w") as fh:
|
|
for r in rows:
|
|
fh.write(json.dumps(r) + "\n")
|
|
os.replace(out + ".tmp", out)
|
|
print("%s rolled: %d people, %d views" % (day, row["people"], row["views"]))
|
|
PY
|