From eaa8799a004ff55964985ea7e4f9c75373095135 Mon Sep 17 00:00:00 2001
From: log
Date: Thu, 25 Jun 2026 22:06:01 +0800
Subject: [PATCH] chore: update restart scripts to use pm2 for production deployment

---
 video-claw/video-claw/restart.bat |   56 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 45 insertions(+), 11 deletions(-)

diff --git a/video-claw/video-claw/restart.bat b/video-claw/video-claw/restart.bat
index 8b24e85..a120720 100644
--- a/video-claw/video-claw/restart.bat
+++ b/video-claw/video-claw/restart.bat
@@ -1,18 +1,52 @@
 @echo off
 chcp 65001 >nul
-echo 正在停止 Video-Claw 服务...
+echo 正在部署 StoriAI 服务 (生产环境)...
 
-for /f "tokens=5" %%p in ('netstat -ano ^| findstr LISTENING ^| findstr :8000') do taskkill /F /PID %%p 2>nul
-for /f "tokens=5" %%p in ('netstat -ano ^| findstr LISTENING ^| findstr :3000') do taskkill /F /PID %%p 2>nul
+where pm2 >nul 2>nul
+if %errorlevel% neq 0 (
+    echo 未检测到 PM2,正在全局安装 PM2...
+    call npm install -g pm2
+)
 
-echo 正在启动后端服务...
-cd backend
-start "Video-Claw Backend" cmd /k ".\venv\Scripts\python.exe api_server.py"
-cd ..
-
-echo 正在启动前端服务...
+echo.
+echo 正在安装和编译前端资源...
 cd frontend
-start "Video-Claw Frontend" cmd /k "npm run dev"
+call npm install
+call npm run build
 cd ..
 
-echo 服务重启完成!前后端已在新的命令行窗口中运行。
+echo.
+echo 正在安装后端依赖...
+cd backend
+if exist ".venv\Scripts\activate.bat" (
+    call .venv\Scripts\activate.bat
+) else if exist "venv\Scripts\activate.bat" (
+    call venv\Scripts\activate.bat
+)
+pip install -r requirements.txt
+cd ..
+
+echo.
+echo 正在使用 PM2 启动服务...
+
+cd backend
+if exist ".venv\Scripts\python.exe" (
+    set PYTHON_BIN=.venv\Scripts\python.exe
+) else if exist "venv\Scripts\python.exe" (
+    set PYTHON_BIN=venv\Scripts\python.exe
+) else (
+    set PYTHON_BIN=python
+)
+call pm2 delete storiai-backend 2>nul
+call pm2 start "%PYTHON_BIN% api_server.py" --name storiai-backend
+cd ..
+
+cd frontend
+call pm2 delete storiai-frontend 2>nul
+call pm2 start "npm run start" --name storiai-frontend
+cd ..
+
+echo.
+echo 部署完成!前端已在 3000 端口,后端已在 8000 端口启动。
+echo 可以使用 'pm2 logs' 查看日志,'pm2 status' 查看运行状态。
+call pm2 save

--
Gitblit v1.8.0