update
This commit is contained in:
@@ -1,70 +1,60 @@
|
||||
#!/bin/bash
|
||||
# start_api_background.sh - 后台启动API服务(生产环境,支持虚拟环境)
|
||||
# start_api_background.sh - 后台启动迁移后的 backend API 服务
|
||||
|
||||
set -e
|
||||
|
||||
VENV_DIR=".venv"
|
||||
BACKEND_PATH="$PWD/backend"
|
||||
|
||||
# 创建日志目录
|
||||
mkdir -p logs
|
||||
|
||||
PID_FILE=logs/api.pid
|
||||
LOG_FILE=logs/api.log
|
||||
|
||||
echo "========================================"
|
||||
echo "后台启动 AI+合规智能中枢 API服务"
|
||||
echo "后台启动 AI+合规智能中枢 API 服务"
|
||||
echo "========================================"
|
||||
echo ""
|
||||
|
||||
# 检查虚拟环境
|
||||
if [ ! -d "$VENV_DIR" ]; then
|
||||
echo "错误: 虚拟环境不存在,请先运行 ./quick_start.sh"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 检查是否已运行
|
||||
if [ -f "$PID_FILE" ]; then
|
||||
PID=$(cat $PID_FILE)
|
||||
if ps -p $PID > /dev/null 2>&1; then
|
||||
PID=$(cat "$PID_FILE")
|
||||
if ps -p "$PID" > /dev/null 2>&1; then
|
||||
echo "服务已在运行 (PID: $PID)"
|
||||
echo "如需重启,请先运行: ./stop_api.sh"
|
||||
exit 1
|
||||
else
|
||||
rm -f $PID_FILE
|
||||
rm -f "$PID_FILE"
|
||||
fi
|
||||
fi
|
||||
|
||||
# 启动参数
|
||||
HOST=${API_HOST:-0.0.0.0}
|
||||
PORT=${API_PORT:-8000}
|
||||
|
||||
echo "服务地址: http://$HOST:$PORT"
|
||||
echo "日志文件: $LOG_FILE"
|
||||
echo ""
|
||||
|
||||
# 后台启动(使用虚拟环境)
|
||||
echo "正在后台启动..."
|
||||
nohup $VENV_DIR/bin/python -m uvicorn src.api.main:app --host $HOST --port $PORT > $LOG_FILE 2>&1 &
|
||||
|
||||
PYTHONPATH="$BACKEND_PATH${PYTHONPATH:+:$PYTHONPATH}" \
|
||||
nohup "$VENV_DIR/bin/python" -m uvicorn app.main:app --host "$HOST" --port "$PORT" > "$LOG_FILE" 2>&1 &
|
||||
PID=$!
|
||||
|
||||
# 保存PID
|
||||
echo $PID > $PID_FILE
|
||||
echo "$PID" > "$PID_FILE"
|
||||
|
||||
# 等待服务启动
|
||||
sleep 3
|
||||
|
||||
# 检查是否启动成功
|
||||
if ps -p $PID > /dev/null 2>&1; then
|
||||
if ps -p "$PID" > /dev/null 2>&1; then
|
||||
echo "服务启动成功 (PID: $PID)"
|
||||
echo ""
|
||||
echo "API地址: http://$HOST:$PORT"
|
||||
echo "API文档: http://$HOST:$PORT/docs"
|
||||
echo "健康检查: http://$HOST:$PORT/health"
|
||||
echo ""
|
||||
echo "前端测试页面:"
|
||||
echo " 直接打开: frontend/index.html"
|
||||
echo " 或启动服务: ./start_frontend.sh"
|
||||
echo ""
|
||||
echo "查看日志:"
|
||||
echo " tail -f $LOG_FILE"
|
||||
echo ""
|
||||
@@ -72,6 +62,6 @@ if ps -p $PID > /dev/null 2>&1; then
|
||||
echo " ./stop_api.sh"
|
||||
else
|
||||
echo "服务启动失败,请查看日志: $LOG_FILE"
|
||||
rm -f $PID_FILE
|
||||
rm -f "$PID_FILE"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user