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

67 lines
1.7 KiB
Batchfile
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.

@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul
echo ====================================
echo 小红书登录服务(浏览器池模式)
echo ====================================
echo.
cd /d %~dp0
REM 检查虚拟环境
if not exist "venv\Scripts\python.exe" (
echo [错误] 未找到虚拟环境,请先运行: python -m venv venv
pause
exit /b 1
)
REM 检查并清理端口8000占用
echo [检查] 正在检查端口8000占用情况...
for /f "tokens=5" %%a in ('netstat -ano ^| findstr :8000 ^| findstr LISTENING') do (
echo [清理] 发现端口8000被进程%%a占用正在清理...
taskkill /F /PID %%a >nul 2>&1
if !errorlevel! equ 0 (
echo [成功] 已清理进程%%a
) else (
echo [警告] 无法清理进程%%a可能需要管理员权限
)
)
REM 等待端口释放
timeout /t 1 /nobreak >nul
echo.
echo [启动] 正在启动Python服务端口8000...
echo [模式] 浏览器池模式 - 性能优化
echo [说明] 浏览器实例将在30分钟无操作后自动清理
echo.
REM 激活虚拟环境并启动服务
echo [Environment] Using virtual environment: %~dp0venv
call "%~dp0venv\Scripts\activate.bat"
if !errorlevel! neq 0 (
echo [错误] 虚拟环境激活失败
pause
exit /b 1
)
REM 显示Python版本和路径
echo.
echo [Python Version]
python --version
echo [Python Path]
where python
echo.
REM 确认使用虚拟环境的Python
echo [Verify] Checking virtual environment...
python -c "import sys; print('Python executable:', sys.executable)"
echo.
REM 启动服务使用虚拟环境的uvicorn
echo [Service] Starting FastAPI service...
echo [Notice] Reload mode disabled for Windows compatibility
python -m uvicorn main:app --host 0.0.0.0 --port 8000
pause