#!/bin/bash # 观察 3 分钟:看门狗能不能把隧道救回来。 set -u URL=https://relay.xxmxxs.top RELAY_DIR=/root/lanremote-relay for i in 1 2 3 4 5 6; do ACTIVE=$(systemctl is-active lanremote-tunnel) HA=$(curl -s --max-time 4 http://127.0.0.1:20241/metrics 2>/dev/null \ | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}') CODE=$(timeout 15 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' "$URL/v1/health" 2>/dev/null) printf " %3ds: 服务=%-8s ha=%-3s 公网=%s\n" \ "$((i * 30))" "$ACTIVE" "${HA:-?}" "${CODE:-超时}" sleep 30 done echo echo " 看门狗最近动作:" tail -8 "$RELAY_DIR/watchdog.log" 2>/dev/null | sed 's/^/ /' echo echo -n " 看门狗状态: " cat "$RELAY_DIR/watchdog.state" 2>/dev/null | tr '\n' ' ' echo echo " 隧道注册/断开: $(grep -c 'Registered tunnel connection' $RELAY_DIR/tunnel.log 2>/dev/null || echo 0) / $(grep -c 'Connection terminated' $RELAY_DIR/tunnel.log 2>/dev/null || echo 0)"