compliance/start_fastapi.sh
2025-08-19 14:44:57 +08:00

53 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
# DMS合规性测试工具 - FastAPI服务器启动脚本
set -e
echo "=== DMS合规性测试工具 FastAPI服务器 ==="
# 默认配置
HOST=${HOST:-"0.0.0.0"}
PORT=${PORT:-"5050"}
WORKERS=${WORKERS:-"1"}
RELOAD=${RELOAD:-"false"}
# 检查Python环境
if ! command -v python3 &> /dev/null; then
echo "[错误] Python3 未安装"
exit 1
fi
# 检查依赖
echo "[信息] 检查依赖..."
if ! python3 -c "import fastapi" &> /dev/null; then
echo "[警告] FastAPI未安装正在安装依赖..."
pip install -r requirements_fastapi.txt
fi
# 创建必要目录
echo "[信息] 创建必要目录..."
mkdir -p test_reports logs uploads
# 启动服务器
echo "[信息] 启动FastAPI服务器..."
echo "[信息] 主机: $HOST"
echo "[信息] 端口: $PORT"
echo "[信息] 工作进程: $WORKERS"
echo "[信息] 自动重载: $RELOAD"
echo ""
echo "[信息] API文档地址: http://$HOST:$PORT/docs"
echo "[信息] ReDoc文档地址: http://$HOST:$PORT/redoc"
echo ""
# 构建启动命令
CMD="python3 fastapi_server.py --host $HOST --port $PORT --workers $WORKERS"
if [ "$RELOAD" = "true" ]; then
CMD="$CMD --reload"
echo "[信息] 开发模式:启用自动重载"
fi
# 启动服务
exec $CMD