#!/bin/bash # 隧道挂了,查原因并恢复。 set -u RELAY_DIR=/root/lanremote-relay echo "===== 1. 服务状态 =====" systemctl status lanremote-tunnel --no-pager 2>&1 | head -10 | sed 's/^/ /' echo echo "===== 2. 进程 =====" pgrep -a -f cloudflared | grep -v grep | sed 's/^/ /' || echo " 没有进程" echo echo "===== 3. 已注册的连接 =====" grep -c 'Registered tunnel connection' "$RELAY_DIR/tunnel.log" 2>/dev/null | sed 's/^/ 注册: /' grep -c 'Connection terminated' "$RELAY_DIR/tunnel.log" 2>/dev/null | sed 's/^/ 断开: /' echo echo " 最近的连接事件:" grep -E 'Registered tunnel connection|Connection terminated|Unable to establish' \ "$RELAY_DIR/tunnel.log" 2>/dev/null | tail -6 | sed 's/^/ /' echo echo "===== 4. 日志尾部 =====" tail -8 "$RELAY_DIR/tunnel.log" 2>/dev/null | sed 's/^/ /' echo echo "===== 5. 到边缘的连通性 =====" echo " region1.v2.argotunnel.com 解析:" getent ahostsv4 region1.v2.argotunnel.com | head -2 | sed 's/^/ /' timeout 10 curl -4 -s -o /dev/null -w ' HTTP %{http_code} %{time_total}s\n' \ https://region1.v2.argotunnel.com 2>/dev/null || echo " 超时" echo echo " UDP 7844 通吗(QUIC 用的端口):" timeout 8 bash -c 'echo > /dev/udp/198.41.200.113/7844' 2>/dev/null && echo " 能发出去" || echo " 发不出去" echo echo "===== 6. 重启隧道 =====" systemctl restart lanremote-tunnel rm -f "$RELAY_DIR/tunnel.log" sleep 40 echo " 服务: $(systemctl is-active lanremote-tunnel)" echo " 注册的连接: $(grep -c 'Registered tunnel connection' "$RELAY_DIR/tunnel.log" 2>/dev/null || echo 0)" echo echo " 日志尾部:" tail -6 "$RELAY_DIR/tunnel.log" 2>/dev/null | sed 's/^/ /' echo echo "===== 7. 验证 =====" OK=0 for i in $(seq 1 10); do C=$(timeout 20 curl -4 -s -o /dev/null -w '%{http_code}' \ -H 'User-Agent: LanRemote/1.4.0' \ https://relay.xxmxxs.top/v1/health 2>/dev/null) [ "$C" = "200" ] && { OK=$((OK + 1)); M="✓"; } || M="✗" printf " %2d: %s HTTP %s\n" "$i" "$M" "${C:-超时}" sleep 3 done echo " 成功 $OK / 10"