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 ++++++++++++++++++++++-----
video-claw/video-claw/restart.sh | 55 +++++++++++++++++----------
2 files changed, 80 insertions(+), 31 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
diff --git a/video-claw/video-claw/restart.sh b/video-claw/video-claw/restart.sh
index 25f36c5..a1e7cb2 100644
--- a/video-claw/video-claw/restart.sh
+++ b/video-claw/video-claw/restart.sh
@@ -1,39 +1,54 @@
#!/bin/bash
-echo "正在停止 Video-Claw 服务..."
+echo "正在部署 StoriAI 服务 (生产环境)..."
-# 查找并终止占用 8000 端口的后端服务
-PID_BACKEND=$(lsof -ti:8000)
-if [ ! -z "$PID_BACKEND" ]; then
- echo "正在关闭后端服务 (PID: $PID_BACKEND)..."
- kill -9 $PID_BACKEND
-fi
-
-# 查找并终止占用 3000 端口的前端服务
-PID_FRONTEND=$(lsof -ti:3000)
-if [ ! -z "$PID_FRONTEND" ]; then
- echo "正在关闭前端服务 (PID: $PID_FRONTEND)..."
- kill -9 $PID_FRONTEND
+# 检查 PM2 是否安装
+if ! command -v pm2 &> /dev/null; then
+ echo "未检测到 PM2,正在全局安装 PM2..."
+ npm install -g pm2
fi
echo ""
-echo "正在启动后端服务..."
+echo "正在安装和编译前端资源..."
+cd frontend
+npm install
+npm run build
+cd ..
+
+echo ""
+echo "正在安装后端依赖..."
cd backend
if [ -d ".venv" ]; then
source .venv/bin/activate
elif [ -d "venv" ]; then
source venv/bin/activate
fi
-nohup python api_server.py > backend_run.log 2>&1 &
-echo "后端服务已在后台启动 (日志: backend/backend_run.log)"
+pip install -r requirements.txt
cd ..
echo ""
-echo "正在启动前端服务..."
+echo "正在使用 PM2 启动服务..."
+
+# 启动后端
+cd backend
+if [ -d ".venv" ]; then
+ PYTHON_BIN=".venv/bin/python"
+elif [ -d "venv" ]; then
+ PYTHON_BIN="venv/bin/python"
+else
+ PYTHON_BIN="python"
+fi
+pm2 delete storiai-backend 2>/dev/null
+pm2 start "$PYTHON_BIN api_server.py" --name storiai-backend
+cd ..
+
+# 启动前端
cd frontend
-nohup npm run dev > frontend_run.log 2>&1 &
-echo "前端服务已在后台启动 (日志: frontend/frontend_run.log)"
+pm2 delete storiai-frontend 2>/dev/null
+pm2 start "npm run start" --name storiai-frontend
cd ..
echo ""
-echo "服务重启完成!"
+echo "部署完成!前端已在 3000 端口,后端已在 8000 端口启动。"
+echo "可以使用 'pm2 logs' 查看日志,'pm2 status' 查看运行状态。"
+pm2 save
--
Gitblit v1.8.0