# -*- coding: utf-8 -*- r'''重启中转并验证 /rescue/,同时查 deploy_release.py 为什么没重启成功。 == 发现的问题 == PID=7255 进程启动于 18:04:35 relay.py 文件改于 18:07:41 进程比文件旧 -> 跑的还是老代码 -> /rescue/ 还是挂。 deploy_release.py 的 --code-only 分支里应该有 systemctl restart, 但显然没生效。两个可能: 1. 那一步的代码路径没走到(--code-only 把 restart 也跳过了) 2. 走了但失败被吞掉 ''' 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''' RELAY=/root/lanremote-relay B=http://127.0.0.1:8080 echo "════ 1. 重启前 ════" PID=$(systemctl show -p MainPID --value lanremote-relay) echo " PID=$PID 启动于 $(ps -o lstart= -p $PID 2>/dev/null)" echo echo "════ 2. 重启 ════" systemctl restart lanremote-relay sleep 5 PID2=$(systemctl show -p MainPID --value lanremote-relay) echo " 新 PID=$PID2 启动于 $(ps -o lstart= -p $PID2 2>/dev/null)" echo " relay.py 改于 $(stat -c '%y' $RELAY/relay.py)" echo " 服务状态: $(systemctl is-active lanremote-relay)" echo echo "════ 3. 重启后测 /rescue/(不带登录,应该立刻 401 而不是挂住)════" printf '报告\n 判断:测试\n' > $RELAY/rescue_reports/19700101-000000-demo.txt echo -n " 不带登录: " curl -s -o /dev/null -w 'HTTP %{http_code} 用时 %{time_total}s\n' --max-time 8 \ "$B/rescue/19700101-000000-demo.txt" PASS=$(cat $RELAY/data/admin_password.txt 2>/dev/null) curl -s -c /tmp/ck2.txt -o /dev/null --max-time 8 -d "password=$PASS" $B/login echo -n " 带登录: " curl -s -b /tmp/ck2.txt -o /tmp/rep2.txt -w 'HTTP %{http_code} 用时 %{time_total}s\n' \ --max-time 8 "$B/rescue/19700101-000000-demo.txt" echo " 内容: $(head -1 /tmp/rep2.txt 2>/dev/null)" echo echo "════ 4. 后台页里的「抢救报告」分区 ════" N=$(curl -s -b /tmp/ck2.txt --max-time 8 $B/zhongzhuanzhan | grep -c '抢救报告') echo " 匹配 $N 次" curl -s -b /tmp/ck2.txt --max-time 8 $B/zhongzhuanzhan | grep -o '19700101-000000-demo.txt' | head -1 | sed 's/^/ 列表里有: /' echo echo "════ 5. 公网还通吗(重启不能把网站弄挂)════" echo " 公网 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/)" rm -f $RELAY/rescue_reports/19700101-000000-demo.txt /tmp/ck2.txt /tmp/rep2.txt ''' def main() -> int: # ---- 先看 deploy_release.py 的 --code-only 分支到底走不走 restart ---- src = (ROOT / "_build" / "deploy_release.py").read_text(encoding="utf-8") print(" ── deploy_release.py 里 restart 相关的代码 ──") for i, ln in enumerate(src.splitlines(), 1): if "restart" in ln or "files_only" in ln or "code_only" in ln: print(" %4d: %s" % (i, ln.strip())) print() 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())