#!/usr/bin/env bash # earth-now.co # Author: Simon-Pierre Boucher # Contact: contact@spboucher.ai # File: infra/tunnel-status.sh # Purpose: Query the ngrok local API on node m3u96b and pretty-print tunnel state + public URL set -euo pipefail REMOTE="m3u96b" echo "== ngrok tunnel status on ${REMOTE} ==" TUNNELS_JSON="$(ssh "${REMOTE}" "curl -s --max-time 5 http://localhost:4040/api/tunnels" 2>/dev/null || true)" if [ -z "${TUNNELS_JSON}" ]; then echo "✗ ngrok is NOT running on ${REMOTE} (no local API on :4040)." echo " Start it with: ssh ${REMOTE} 'cd ~/earth-now && ngrok start --config infra/ngrok.yml earth-now'" exit 1 fi python3 - "$TUNNELS_JSON" <<'PYEOF' # Pretty-print the ngrok /api/tunnels payload passed as argv[1]. import json import sys try: data = json.loads(sys.argv[1]) except json.JSONDecodeError: print("✗ ngrok local API returned non-JSON output — agent may be starting up or misconfigured.") sys.exit(1) tunnels = data.get("tunnels", []) if not tunnels: print("✗ ngrok agent is running but NO tunnels are established.") sys.exit(1) for t in tunnels: name = t.get("name", "?") public_url = t.get("public_url", "?") proto = t.get("proto", "?") addr = t.get("config", {}).get("addr", "?") conns = t.get("metrics", {}).get("conns", {}).get("count", "?") print(f"✓ tunnel '{name}' [{proto}] {public_url} → {addr} (connections: {conns})") PYEOF