# -*- coding: utf-8 -*- r'''查 nettune 为什么卡在 activating(它挡着隧道,隧道一挂网站就 530)。 发现: lanremote-nettune activating <- 卡住 lanremote-tunnel inactive <- 在等 nettune lanremote-tunnel-h2 inactive 公网 530 nettune 的 unit 里有 Before=lanremote-tunnel.service, 所以它卡住 = 隧道永远起不来。 ''' 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. nettune 的完整状态 ════" systemctl status lanremote-nettune --no-pager -n 25 2>&1 | tail -25 echo echo "════ 2. 有没有卡住的子进程 ════" systemctl show -p MainPID -p ControlPID -p ExecMainStatus -p StateChangeTimestamp lanremote-nettune 2>&1 echo " --- 所有相关进程 ---" ps -eo pid,ppid,stat,etime,cmd 2>/dev/null | grep -E 'iptables|net-tune|deploy-tune|ip link' | grep -v grep echo echo "════ 3. net-tune.sh 里会不会卡住的那步 ════" echo " --- 脚本第 4 步(重启隧道)会 wait 吗 ---" grep -n 'systemctl restart' /root/lanremote-relay/net-tune.sh echo echo "════ 4. 手动跑一次 net-tune.sh 看卡在哪(30 秒超时)════" timeout 30 bash /root/lanremote-relay/net-tune.sh 2>&1 | tail -15 echo " 退出码: $?" echo echo "════ 5. 卡住的时候隧道是什么状态 ════" systemctl is-active lanremote-tunnel lanremote-tunnel-h2 journalctl -u lanremote-tunnel --no-pager -n 12 2>/dev/null | tail -12 ''' 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())