18 lines
588 B
Bash

#!/bin/bash
# Auto-restarting cloudflared tunnel for nichequiz
while true; do
echo "[$(date)] Starting tunnel..."
cloudflared tunnel --url http://localhost:8877 --protocol http2 2>&1 | tee -a /tmp/nichequiz-tunnel-latest.log &
TUNNEL_PID=$!
# Wait for URL to appear
sleep 8
TUNNEL_URL=$(grep -o 'https://[a-z0-9-]*\.trycloudflare\.com' /tmp/nichequiz-tunnel-latest.log | tail -1)
echo "[$(date)] Tunnel URL: $TUNNEL_URL"
# Wait for tunnel process to die
wait $TUNNEL_PID
echo "[$(date)] Tunnel died. Restarting in 3s..."
sleep 3
done