@echo off chcp 65001 >nul setlocal enabledelayedexpansion echo ================================================ echo agent_jrxml 启动 (全栈) echo ================================================ cd /d "%~dp0" :: ── 环境检查 ── if not exist "%~dp0.venv\Scripts\python.exe" ( echo [错误] 未找到 .venv,请先创建虚拟环境 pause exit /b 1 ) if not exist "%~dp0frontend\node_modules" ( echo [安装] node_modules 不存在,正在 npm install... cd /d "%~dp0frontend" call npm install cd /d "%~dp0" ) echo. :: ── 清理残留进程 ── call :killport 8000 call :killport 8001 call :killport 5173 echo. :: ── 1. 验证服务 ── echo [1/3] 启动验证服务 :8001 ... start "jrxml-validator" .venv\Scripts\python.exe -c "import uvicorn; uvicorn.run('validation_service.main:app',host='0.0.0.0',port=8001,reload=False)" 2> "%~dp0logs\validator-stderr.log" call :wait_health "8001" "验证服务" || goto cleanup echo :8001 就绪 :: ── 2. API 服务 ── echo [2/3] 启动 API 服务 :8000 ... start "jrxml-api" .venv\Scripts\python.exe -c "import uvicorn; uvicorn.run('api_server:app',host='0.0.0.0',port=8000,reload=False)" 2> "%~dp0logs\api-stderr.log" call :wait_health "8000/api" "API 服务" || goto cleanup echo :8000 就绪 :: ── 3. 前端 ── echo [3/3] 启动前端 :5173 ... cd /d "%~dp0frontend" start "jrxml-frontend" cmd /c "npm run dev" 2> "%~dp0logs\frontend-stderr.log" cd /d "%~dp0" call :wait_port "5173" "前端" || goto cleanup echo :5173 就绪 echo. echo ================================================ echo 全部就绪: echo 前端: http://localhost:5173 echo API: http://localhost:8000/docs echo 验证: http://localhost:8001/health echo 运行 stop.bat 停止所有服务 echo ================================================ pause exit /b 0 :: ── Cleanup ── :cleanup echo [清理] 停止已启动的服务... taskkill /F /FI "WINDOWTITLE eq jrxml-validator*" >nul 2>&1 taskkill /F /FI "WINDOWTITLE eq jrxml-api*" >nul 2>&1 taskkill /F /FI "WINDOWTITLE eq jrxml-frontend*" >nul 2>&1 call :killport 8001 call :killport 8000 call :killport 5173 echo 已清理,请重试 pause exit /b 1 :: ── Helper: kill process on port ── :killport for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":%1.*LISTENING"') do ( echo 清理端口 %1 (PID %%a) taskkill /F /PID %%a >nul 2>&1 ) exit /b 0 :: ── Helper: wait for HTTP health check ── :wait_health set /a N=0 :wait_health_loop ping -n 2 127.0.0.1 >nul powershell -Command "try{$r=Invoke-WebRequest -Uri http://localhost:%1/health -TimeoutSec 2 -UseBasicParsing;exit 0}catch{exit 1}" >nul 2>&1 if not errorlevel 1 exit /b 0 set /a N+=1 if !N! GEQ 30 exit /b 1 goto wait_health_loop :: ── Helper: wait for TCP port ── :wait_port set /a N=0 :wait_port_loop ping -n 3 127.0.0.1 >nul netstat -ano | findstr ":%1.*LISTENING" >nul 2>&1 if not errorlevel 1 exit /b 0 set /a N+=1 if !N! GEQ 30 exit /b 1 goto wait_port_loop