← back to Allnewsdaily
scripts/push-live-status.sh
29 lines
#!/usr/bin/env bash
# Run the YouTube live-check locally (this Mac has a residential IP that YouTube serves the real
# watch page to) then rsync ONLY data/live-status.json to prod, which runs with LIVE_STATIC=1 and
# does NOT run its own checker (prod's datacenter IP gets a consent/bot wall → 0 live).
# Runs from a launchd job on this Mac every ~2 min. Reversible: unload the job to stop.
set -euo pipefail
cd "$(dirname "$0")/.."
PROD="${PROD_HOST:-root@45.61.58.125}"
REMOTE="/root/Projects/allnewsdaily/data/live-status.json"
# Resolve node robustly (launchd has a minimal PATH).
NODE="$(command -v node || true)"
for cand in /opt/homebrew/bin/node /usr/local/bin/node /usr/bin/node; do
[ -z "$NODE" ] && [ -x "$cand" ] && NODE="$cand"
done
[ -n "$NODE" ] || { echo "[push-live] node not found"; exit 3; }
"$NODE" scripts/check-live.js || { echo "[push-live] check failed, not pushing"; exit 1; }
# only push a valid JSON object
"$NODE" -e "const s=require('./data/live-status.json'); if(typeof s!=='object'||Array.isArray(s)){process.exit(2)}" || { echo "[push-live] live-status.json invalid, not pushing"; exit 2; }
rsync -az -e "ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new" data/live-status.json "$PROD:$REMOTE"
# Drop the sentinel so prod enters static-live mode (its own checker self-disables — no prod env
# change, no restart). Idempotent; survives deploys because data/ is excluded from rsync --delete.
ssh -o ConnectTimeout=10 -o StrictHostKeyChecking=accept-new "$PROD" \
"touch /root/Projects/allnewsdaily/data/live-static.flag" || true
echo "[push-live] pushed $(date -u +%FT%TZ) → $PROD:$REMOTE (+ static flag)"