# -*- coding: utf-8 -*- r'''修设备上的几个卡住的状态。 发现的问题: 1. lanremote-tunnel(主隧道)inactive —— 只剩 h2 副本在跑, 公网返回 530。这是网站"挂了"的直接原因。 2. lanremote-nettune 卡在 activating —— 所以 MTU 还是 1400 (而实测 1400 反而掉到 50%)。 3. monitor.timer 没起来。 按顺序修,每步都验。 ''' 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 STEPS = [ ("1. 看 nettune 为什么卡住(它挡着 MTU)", "systemctl status lanremote-nettune --no-pager -n 12 2>&1 | tail -12; " "echo '--- 有没有残留的 iptables 进程 ---'; pgrep -a iptables || echo 无"), ("2. 把卡住的 nettune 停掉、直接跑一次 net-tune.sh", "systemctl stop lanremote-nettune 2>/dev/null; " "systemctl reset-failed lanremote-nettune 2>/dev/null; " "bash /root/lanremote-relay/net-tune.sh 2>&1 | tail -12; " "echo '--- 结果 ---'; " "echo \"MTU=$(cat /sys/class/net/wlan0/mtu)\"; " "echo \"MSS 规则=$(iptables -t mangle -L -n 2>/dev/null | grep -ci mss) 条\""), ("3. 拉起主隧道(网站 530 的直接原因)", "systemctl reset-failed lanremote-tunnel 2>/dev/null; " "systemctl restart lanremote-tunnel; sleep 12; " "systemctl is-active lanremote-tunnel; " "systemctl is-active lanremote-tunnel-h2"), ("4. 重启中转(让新的 admin.py 生效,后台才有「抢救报告」分区)", "systemctl restart lanremote-relay; sleep 4; " "systemctl is-active lanremote-relay"), ("5. 启用监测定时器", "systemctl enable lanremote-monitor.timer >/dev/null 2>&1; " "systemctl start lanremote-monitor.timer; sleep 3; " "systemctl is-active lanremote-monitor.timer"), ("6. 验证:公网通了没 / 隧道连接数 / 后台分区", "echo \"公网 /v1/health: $(curl -s -o /dev/null -w '%{http_code}' " "--max-time 20 https://relay.xxmxxs.top/v1/health)\"; " "echo \"公网首页: $(curl -s -o /dev/null -w '%{http_code}' " "--max-time 20 https://relay.xxmxxs.top/)\"; " "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 \"后台「抢救报告」出现次数: " "$(curl -s --max-time 8 http://127.0.0.1:8080/zhongzhuanzhan " "| grep -c '抢救报告')\""), ] def main() -> int: for title, cmd in STEPS: print() print("=" * 66) print(" " + title) print("=" * 66) try: out = run(cmd, timeout=180) text = out[1] if isinstance(out, tuple) else str(out) except Exception as exc: # noqa: BLE001 text = " [执行失败] %s: %s" % (type(exc).__name__, exc) for ln in text.strip().splitlines(): print(" " + ln) return 0 if __name__ == "__main__": sys.exit(main())