#!/usr/bin/env bash
# M7 smoke runner: stops the archiverd service first to release the
# advisory lock, then runs the canonical 4-step M7 smoke.
#
# This wrapper exists because:
#   - The archiverd compose service runs in an hourly loop with first-run
#     immediate, so it would race the smoke's one-shot exec for the
#     pg_try_advisory_lock(0xBA21B0DA). Only one wins per cycle, and the
#     smoke needs the deterministic one.
#   - The canonical smoke (scripts/m7_smoke.sh) hardcodes the project
#     prefix `broad-announce-` and uses `docker exec` + `curl localhost`
#     which all resolve correctly on a remote host that has the stack up
#     under that compose project name.
#
# Usage:
#   cd /root/broad-announce
#   bash scripts/m7_smoke_runner.sh
#
# Exits with the smoke's exit code.

set -e
cd "$(dirname "$0")/.."

echo "=== pre-smoke: stop archiverd (release the advisory lock) ==="
docker compose stop archiverd 2>&1 | tail -3
echo

echo "=== run the M7 smoke ==="
bash scripts/m7_smoke.sh
