Files
PlantAI-dev/apps/web/vue3/start_server.sh
T
2026-08-03 18:42:47 +08:00

49 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# BBAV20311 服务启动脚本 - 带自动重启
PROJECT_DIR="/home/xzq/5090/PlantAI-dev4090-7/PlantAI-dev"
LOG_FILE="/tmp/bbav5_vue3.log"
PID_FILE="/tmp/bbav5_vue3.pid"
cd "$PROJECT_DIR/apps/web/vue3"
# 如果服务已在运行,先停止
if [ -f "$PID_FILE" ]; then
OLD_PID=$(cat "$PID_FILE")
if ps -p "$OLD_PID" > /dev/null 2>&1; then
echo "停止旧服务 (PID: $OLD_PID)..."
kill "$OLD_PID" 2>/dev/null
sleep 2
fi
fi
# 清理日志
echo "=== 服务启动 $(date) ===" > "$LOG_FILE"
# 启动服务并监控
while true; do
echo "启动服务..."
python3 main.py >> "$LOG_FILE" 2>&1 &
PID=$!
echo $PID > "$PID_FILE"
echo "服务已启动,PID: $PID"
# 等待服务退出
wait $PID
EXIT_CODE=$?
echo "服务退出,退出码: $EXIT_CODE,$(date)" >> "$LOG_FILE"
# 检查是否是正常停止(SIGTERM = 143, SIGINT = 130)
if [ $EXIT_CODE -eq 0 ] || [ $EXIT_CODE -eq 130 ] || [ $EXIT_CODE -eq 143 ]; then
echo "服务正常停止,不重启"
break
fi
echo "服务异常退出,5秒后重启..."
sleep 5
done
rm -f "$PID_FILE"