# -*- coding: utf-8 -*- r'''查隧道为什么掉连接(公网 530,连接数 1/0)。 上一轮才刚修掉 nettune 死锁、把公网拉到 200;这次重启 nettune 之后 又变成 530 了。要分清是: * nettune 又卡了(那个死锁没修干净?) * 还是隧道自己掉了(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''' echo "════ 1. 服务状态 + 有没有卡住的 ════" for s in lanremote-relay lanremote-tunnel lanremote-tunnel-h2 lanremote-nettune; do printf ' %-24s %s\n' "$s" "$(systemctl is-active $s)" done echo " --- nettune 卡住吗 ---" systemctl show -p SubState -p MainPID -p ExecMainStartTimestamp lanremote-nettune 2>&1 | sed 's/^/ /' echo " --- 有没有卡住的 systemctl ---" ps -eo pid,etime,cmd 2>/dev/null | grep -E 'systemctl|net-tune' | grep -v grep | sed 's/^/ /' echo echo "════ 2. net-tune 的修复在设备上吗 ════" grep -c NETTUNE_SERVICE_CALL /root/lanremote-relay/net-tune.sh echo " unit 里有吗: $(grep -c NETTUNE_SERVICE_CALL /etc/systemd/system/lanremote-nettune.service)" echo echo "════ 3. 隧道为什么连接数是 0 ════" journalctl -u lanremote-tunnel --no-pager -n 25 2>/dev/null | tail -25 | sed 's/^/ /' echo echo "════ 4. 隧道 unit 长什么样(重启策略 / 协议)════" systemctl cat lanremote-tunnel 2>/dev/null | grep -vE '^#' | head -25 | sed 's/^/ /' echo echo "════ 5. cloudflared 进程 ════" ps -eo pid,etime,rss,cmd 2>/dev/null | grep cloudflared | grep -v grep | sed 's/^/ /' ''' 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())