Files
ai_wht_wechat/backend/start_service.sh
2026-01-06 19:36:42 +08:00

51 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
echo "===================================="
echo " 小红书登录服务(浏览器池模式)"
echo "===================================="
echo ""
cd "$(dirname "$0")"
# 检查虚拟环境
if [ ! -f "venv/bin/python" ]; then
echo "[错误] 未找到虚拟环境,请先运行: python3 -m venv venv"
exit 1
fi
# 检查并清理端口8000占用
echo "[检查] 正在检查端口8000占用情况..."
PID=$(lsof -ti:8000)
if [ ! -z "$PID" ]; then
echo "[清理] 发现端口8000被进程$PID占用,正在清理..."
kill -9 $PID 2>/dev/null
if [ $? -eq 0 ]; then
echo "[成功] 已清理进程$PID"
else
echo "[警告] 无法清理进程$PID可能需要sudo权限"
fi
sleep 1
fi
echo ""
echo "[启动] 正在启动Python服务端口8000..."
echo "[模式] 浏览器池模式 - 性能优化"
echo "[说明] 浏览器实例将在30分钟无操作后自动清理"
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 ""
# 启动服务使用虚拟环境的uvicorn
echo "[Notice] Reload mode disabled for Windows compatibility"
python -m uvicorn main:app --host 0.0.0.0 --port 8000