From bb934228dba81b1da03b9084a6d8c60adf0ed33a Mon Sep 17 00:00:00 2001 From: claude_dev Date: Sun, 16 Aug 2026 18:07:02 +0800 Subject: [PATCH] =?UTF-8?q?feat(ci):=20vps-deploy=E6=9C=AB=E6=AD=A5?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=87=8D=E5=90=AF=E5=B8=B8=E9=A9=BB=E8=BF=9B?= =?UTF-8?q?=E7=A8=8B(supervisor/=E5=BD=B1=E5=AD=90=E6=9F=9C=E5=8F=B0)?= =?UTF-8?q?=E2=80=94=E2=80=94=E6=A0=B9=E5=9B=A0:=E9=83=A8=E7=BD=B2?= =?UTF-8?q?=E5=8F=AA=E6=8E=A8=E7=A0=81+=E9=87=8D=E5=90=AFAPI,=E5=B8=B8?= =?UTF-8?q?=E9=A9=BBpython=E8=BF=9B=E7=A8=8B16h=E8=B7=91=E6=97=A7=E4=BB=A3?= =?UTF-8?q?=E7=A0=81(2026-08-15=E5=AE=9E=E5=BD=95);vps=5Frestart=5Fresiden?= =?UTF-8?q?t.sh:=E7=9B=98=E4=B8=AD=E4=BF=9D=E6=8A=A4(=E5=8C=97=E4=BA=AC?= =?UTF-8?q?=E5=B7=A5=E4=BD=9C=E6=97=A509:15-15:30=E8=B7=B3=E8=BF=87?= =?UTF-8?q?=E9=98=B2=E6=9D=80=E6=92=AE=E5=90=88=E7=8E=B0=E5=9C=BA)+?= =?UTF-8?q?=E5=8A=A8=E6=80=81=E6=9F=A5PID(=E8=B4=A6=E6=88=B7=E5=8F=B7?= =?UTF-8?q?=E4=BC=9A=E5=8F=98,name=3Dpython.exe+sanguo=5Flive=20supervisor?= =?UTF-8?q?/sanguo=5Ftrader.shadow=E4=B8=A4=E6=A8=A1=E5=BC=8F,=E5=85=8Dwmi?= =?UTF-8?q?c=E8=87=AA=E5=8C=B9=E9=85=8D)+taskkill=20/F=20/T=E6=9D=80?= =?UTF-8?q?=E6=A0=91=E5=B8=A6=E8=B5=B0runner=5Flive/shadow=E5=AD=90?= =?UTF-8?q?=E8=BF=9B=E7=A8=8B+schtasks=E9=87=8D=E6=8B=89+120s=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E2=89=A52=E8=BF=9B=E7=A8=8B;=E7=94=A8=E6=88=B72026-08?= =?UTF-8?q?-16=E8=A6=81=E6=B1=82=E9=83=A8=E7=BD=B2=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96=20[nas]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/vps-deploy.yml | 2 + scripts/nas_sync/vps_restart_resident.sh | 54 ++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 scripts/nas_sync/vps_restart_resident.sh diff --git a/.gitea/workflows/vps-deploy.yml b/.gitea/workflows/vps-deploy.yml index 2deea0a..1784a24 100644 --- a/.gitea/workflows/vps-deploy.yml +++ b/.gitea/workflows/vps-deploy.yml @@ -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 }} diff --git a/scripts/nas_sync/vps_restart_resident.sh b/scripts/nas_sync/vps_restart_resident.sh new file mode 100644 index 0000000..a933f22 --- /dev/null +++ b/scripts/nas_sync/vps_restart_resident.sh @@ -0,0 +1,54 @@ +#!/bin/bash +# VPS 常驻进程滚动重启(sanguo-live-supervisor + sanguo-shadow-desk)。 +# +# 为什么需要:vps-deploy 只推代码+重启 sanguo-api;supervisor/影子柜台是常驻 +# 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