# -*- coding: utf-8 -*- r'''看隧道为什么反复掉(公网 530 的真因)。 已知: nettune 死锁已修(SubState=exited,不再卡) 但隧道每 3~10 分钟被重启一次(部分是我加的预案在救、部分是它自己掉) 公网 530 要查的是 tunnel.log 里 cloudflared 到底在报什么。 ''' from __future__ import annotations import sys from pathlib import Path ROOT = Path(__file__).resolve().parent.parent sys.path.insert(0, str(ROOT / "_build")) from devssh import run # noqa: E402 REMOTE = r''' LOG=/root/lanremote-relay/tunnel.log H2LOG=/root/lanremote-relay/tunnel-h2.log echo "════ 1. tunnel.log 里的错误行(最近 40 条)════" grep -iE 'error|fail|warn|timeout|retry|refused|EOF|unregister|connection' "$LOG" 2>/dev/null | tail -40 | sed 's/^/ /' echo echo "════ 2. tunnel.log 最后 25 行(原样)════" tail -25 "$LOG" 2>/dev/null | sed 's/^/ /' echo echo "════ 3. h2 那份的日志 ════" tail -15 "$H2LOG" 2>/dev/null | sed 's/^/ /' echo echo "════ 4. 两份日志多大(写爆了会拖慢小机器)════" ls -la "$LOG" "$H2LOG" 2>/dev/null | sed 's/^/ /' echo echo "════ 5. cloudflared 版本 + 配置 ════" /usr/local/bin/cloudflared --version 2>&1 | sed 's/^/ /' echo " --- config.yml ---" cat /root/.cloudflared/config.yml 2>/dev/null | sed 's/^/ /' echo echo "════ 6. 现在两条隧道的连接数 ════" for p in 20241 20242; do n=$(curl -s --max-time 5 "http://127.0.0.1:$p/metrics" 2>/dev/null | grep '^cloudflared_tunnel_ha_connections' | awk '{print $2}' | head -1) echo " $p -> ${n:-拿不到}" done echo echo "════ 7. 公网现在通吗 ════" echo " $(curl -s -o /dev/null -w '%{http_code}' --max-time 15 https://relay.xxmxxs.top/v1/health)" ''' def main() -> int: out = run(REMOTE, timeout=300) text = out[1] if isinstance(out, tuple) else str(out) print(text) return 0 if __name__ == "__main__": sys.exit(main())