Files
ai_wht_wechat/backend/start_prod.sh
2026-01-07 10:42:04 +08:00

50 lines
1.4 KiB
Bash
Raw Permalink 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
# 小红书Python服务启动脚本生产环境
cd "$(dirname "$0")"
echo "========================================"
echo " 小红书登录服务(生产模式)"
echo "========================================"
echo ""
# 激活虚拟环境
echo "[环境] 激活虚拟环境: $(pwd)/venv"
source venv/bin/activate
if [ $? -ne 0 ]; then
echo "[错误] 虚拟环境激活失败"
exit 1
fi
# 显示Python版本和路径
echo "[Python] $(python --version)"
echo "[路径] $(which python)"
echo ""
# 检查是否安装了Xvfb
if command -v xvfb-run &> /dev/null; then
echo "[Xvfb] 检测到Xvfb将使用虚拟显示运行避免无头模式被检测"
USE_XVFB=true
else
echo "[警告] 未检测到Xvfb将使用无头模式可能触发验证"
echo "[提示] 安装Xvfb: sudo apt-get install -y xvfb"
USE_XVFB=false
fi
echo ""
echo "[启动] 正在启动Python服务生产环境端口8000..."
echo "[说明] 按Ctrl+C停止服务"
echo ""
# 设置环境为生产环境
export ENV=prod
# 启动服务根据是否有Xvfb选择启动方式
if [ "$USE_XVFB" = true ]; then
echo "[模式] 使用Xvfb虚拟显示 + 有头模式"
xvfb-run --auto-servernum --server-args="-screen 0 1920x1080x24" python -m uvicorn main:app --host 0.0.0.0 --port 8000
else
echo "[模式] 无头模式(可能被检测)"
python -m uvicorn main:app --host 0.0.0.0 --port 8000
fi