feat(ci): vps-deploy末步自动重启常驻进程(supervisor/影子柜台)——根因:部署只推码+重启API,常驻python进程16h跑旧代码(2026-08-15实录);vps_restart_resident.sh:盘中保护(北京工作日09:15-15:30跳过防杀撮合现场)+动态查PID(账户号会变,name=python.exe+sanguo_live supervisor/sanguo_trader.shadow两模式,免wmic自匹配)+taskkill /F /T杀树带走runner_live/shadow子进程+schtasks重拉+120s验证≥2进程;用户2026-08-16要求部署自动化 [nas]
CI/CD / test (push) Successful in 13s
CI/CD / nas-deploy (push) Successful in 31s
CI/CD / nas-verify (push) Successful in 11s

This commit is contained in:
2026-08-16 18:07:02 +08:00
parent bfd42f70ae
commit bb934228db
2 changed files with 56 additions and 0 deletions
+2
View File
@@ -86,6 +86,8 @@ jobs:
sleep 10
done
echo "API 监听但 /docs 2 分钟未返回 200"; exit 1
- name: 重启 VPS 常驻进程 (supervisor/影子柜台吃新代码; 盘中自动跳过)
run: bash scripts/nas_sync/vps_restart_resident.sh
- name: mark vps-deployed tag (VPS 版本真相, session 用 git log vps-deployed..HEAD 查未部署)
env:
TOKEN: ${{ github.token }}
+54
View File
@@ -0,0 +1,54 @@
#!/bin/bash
# VPS 常驻进程滚动重启(sanguo-live-supervisor + sanguo-shadow-desk)。
#
# 为什么需要:vps-deploy 只推代码+重启 sanguo-apisupervisor/影子柜台是常驻
# python 进程,不重启就一直跑旧代码(2026-08-15 实录:部署后 16h 旧进程原样跑)。
#
# 用法:
# bash scripts/nas_sync/vps_restart_resident.sh # 直接执行(Mac runner / 本机)
#
# 盘中保护:北京时间 工作日 09:15-15:30 跳过重启(盘中杀树丢撮合现场),
# 打印 SKIP_RESIDENT_RESTART 并 exit 0 —— 代码已就位,下次非盘中部署/手动补跑生效。
set -u
VPS=49.232.102.198
SSH="ssh -o ControlPath=none -o ConnectTimeout=20 $VPS"
# ---- 1) 盘中保护 ----
BJ_HM=$(TZ=Asia/Shanghai date +%H%M)
BJ_DOW=$(TZ=Asia/Shanghai date +%u)
if [ "$BJ_DOW" -le 5 ] && [ "$BJ_HM" -ge 0915 ] && [ "$BJ_HM" -le 1530 ]; then
echo "SKIP_RESIDENT_RESTART 北京时间盘中(周$BJ_DOW $BJ_HM)——supervisor/影子保持运行,下次非盘中部署生效"
exit 0
fi
# ---- 2) 查 supervisor/影子 python 进程树根(动态查 PID:账户号会变)----
PIDS=$($SSH "wmic process where \"name='python.exe' and (commandline like '%sanguo_live%supervisor%' or commandline like '%sanguo_trader.shadow%')\" get processid /format:csv" 2>/dev/null \
| tr -d '\r' | grep -oE '[0-9]+$' | sort -u || true)
echo "重启前进程: $(echo $PIDS | tr '\n' ' ')"
# ---- 3) 杀全树(/T 带走 runner_live / shadow --account 子进程)----
for pid in $PIDS; do
$SSH "taskkill /F /T /PID $pid" 2>/dev/null || echo " (PID $pid 已自行退出)"
done
# schtask 收尸(壳可能残留 running 态,end 掉才好 /run
$SSH "schtasks /end /tn sanguo-live-supervisor" 2>/dev/null || true
$SSH "schtasks /end /tn sanguo-shadow-desk" 2>/dev/null || true
# ---- 4) 重拉 ----
sleep 3
$SSH "schtasks /run /tn sanguo-live-supervisor" || { echo "❌ supervisor 拉起失败"; exit 1; }
$SSH "schtasks /run /tn sanguo-shadow-desk" || { echo "❌ shadow-desk 拉起失败"; exit 1; }
# ---- 5) 等进程回来(内存实测 40-60s 起齐,给 120s 余量)----
for i in $(seq 1 12); do
sleep 10
GOT=$($SSH "wmic process where \"name='python.exe' and (commandline like '%sanguo_live%supervisor%' or commandline like '%sanguo_trader.shadow%')\" get processid /format:csv" 2>/dev/null \
| tr -d '\r' | grep -cE '[0-9]+$' || true)
echo " ${i}0s: 已起 $GOT 个进程"
if [ "${GOT:-0}" -ge 2 ]; then
echo "RESIDENT_RESTART_DONE supervisor+影子已重启并吃上新代码"
exit 0
fi
done
echo "❌ 120s 内常驻进程未起齐(期望≥2: supervisor+shadow auto)"
exit 1