# -*- coding: utf-8 -*- r'''停掉旧那台随身 WiFi 服务器上的中转。 == 为什么可以停 == 中转已经搬到 AWS Lightsail(有公网 IP、域名 yk.xxmxxs.top、 经 Cloudflare CDN),旧机器上那套(lanremote-relay + 两条 Cloudflare 隧道 + 网络调优)全部不再需要。 旧那套的问题回顾(都是停掉它的理由): * 线路对隧道 7844 端口间歇性阻断 -> 隧道每 3~10 分钟掉一次 * 只有 460MB 内存 * 会掉电硬挂(2026-10-08 18:42 一次非正常关机) == 停的方式:**只停服务,不关机、不删东西** == 用户说的是"可以停了"。按最小动作来: * systemctl stop + disable 那几个服务 * **不**关机(万一还想上去看日志) * **不**删任何文件(可逆) 这样如果新服务器出问题,随时可以 systemctl start 回去。 等新服务器稳定跑一阵,再彻底关机/退订也不迟。 ''' 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 SERVICES = [ "lanremote-relay", "lanremote-tunnel", "lanremote-tunnel-h2", "lanremote-nettune", "lanremote-monitor.timer", "lanremote-watchdog.timer", ] def main() -> int: print("=" * 62) print(" 停掉旧服务器(4G 小机器)上的中转") print("=" * 62) print() print(" ── 停之前的状态 ──") out = run("for s in %s; do printf ' %%-26s %%s\\n' $s " "\"$(systemctl is-active $s 2>&1)\"; done" % " ".join(SERVICES), timeout=120, quiet=True) for ln in out[1].strip().splitlines(): print(ln) print() print(" ── 停掉 + 取消开机自启 ──") # 先停 timer(免得它刚好在停服务的时候又触发一次抢救) out = run( "sudo systemctl disable --now lanremote-monitor.timer " "lanremote-watchdog.timer 2>&1 | tail -2; " "for s in lanremote-relay lanremote-tunnel lanremote-tunnel-h2 " "lanremote-nettune; do " " sudo systemctl disable --now $s 2>&1 | tail -1; " "done; echo DONE", timeout=300, quiet=True) for ln in out[1].strip().splitlines()[-12:]: print(" " + ln) print() print(" ── 停之后的状态 ──") out = run("for s in %s; do printf ' %%-26s %%s\\n' $s " "\"$(systemctl is-active $s 2>&1)\"; done" % " ".join(SERVICES), timeout=120, quiet=True) for ln in out[1].strip().splitlines(): print(ln) print() print(" ── 顺带停掉 cloudflared(隧道进程)──") out = run("pgrep -a cloudflared | head -4; " "sudo pkill -f cloudflared 2>/dev/null; sleep 2; " "echo ' 剩余 cloudflared 进程: '\$(pgrep -c cloudflared " "2>/dev/null || echo 0)", timeout=120, quiet=True) for ln in out[1].strip().splitlines(): print(" " + ln) print() print(" ── 确认网站上不去了(relay.xxmxxs.top 应该 5xx)──") out = run("echo \" relay.xxmxxs.top -> $(curl -s -o /dev/null " "-w '%%{http_code}' --max-time 15 " "https://relay.xxmxxs.top/v1/health)\"", timeout=120, quiet=True) for ln in out[1].strip().splitlines(): print(" " + ln) print() print(" 说明:**只停了服务,没关机、没删文件** ——") print(" 万一新服务器有问题,随时可以 start 回去:") print(" sudo systemctl enable --now lanremote-relay " "lanremote-tunnel lanremote-tunnel-h2") print(" 等新服务器稳定跑几天,再考虑关机/退订。") return 0 if __name__ == "__main__": sys.exit(main())