fix: replace complex bat scripts with Python launcher + minimal bat wrappers

Root cause: Windows batch files written with LF endings caused cmd.exe to
misparse labels and Chinese characters, producing garbled "not a command"
errors. The Python launcher avoids encoding issues entirely.

- start.py: reliable cross-platform launcher (kill ports, start 3 services,
  wait for health, print status)
- start.bat / start_all.bat: minimal 4-line ASCII wrappers
- stop.bat: inline Python for port-based process killing
This commit is contained in:
2026-05-23 09:32:32 +08:00
parent c8924c625c
commit c2cae5665e
4 changed files with 150 additions and 193 deletions
+1 -69
View File
@@ -1,72 +1,4 @@
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
echo ================================================
echo agent_jrxml 启动 (API + 验证)
echo ================================================
cd /d "%~dp0"
:: ── 环境检查 ──
if not exist "%~dp0.venv\Scripts\python.exe" (
echo [错误] 未找到 .venv,请先创建虚拟环境
pause
exit /b 1
)
echo.
:: ── 清理残留进程 ──
echo [清理] 检查残留进程...
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":8000.*LISTENING"') do (
taskkill /F /PID %%a >nul 2>&1 && echo 已清理端口 8000 (PID %%a)
)
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":8001.*LISTENING"') do (
taskkill /F /PID %%a >nul 2>&1 && echo 已清理端口 8001 (PID %%a)
)
echo.
:: ── 1. 验证服务 ──
echo [启动] 验证服务 :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"
echo [等待] 验证服务就绪...
set /a N=0
:wait_val
ping -n 2 127.0.0.1 >nul
powershell -Command "try{$r=Invoke-WebRequest -Uri http://localhost:8001/health -TimeoutSec 2 -UseBasicParsing;exit 0}catch{exit 1}" >nul 2>&1
if not errorlevel 1 goto val_ok
set /a N+=1
if !N! GEQ 30 (
echo [失败] 验证服务启动超时 (30次重试)
echo 请检查: logs\validator-stderr.log
goto cleanup
)
goto wait_val
:val_ok
echo :8001 就绪
:: ── 2. API 服务 (前台运行) ──
echo [启动] API 服务 :8000
echo ================================================
echo 服务已就绪:
echo API: http://localhost:8000/docs
echo 验证: http://localhost:8001/health
echo 按 Ctrl+C 停止 API 服务
echo 关闭窗口后会自动清理验证服务
echo ================================================
.venv\Scripts\python.exe -c "import uvicorn; uvicorn.run('api_server:app',host='0.0.0.0',port=8000,reload=False)"
:: ── API 退出后清理 ──
echo.
echo [清理] 停止验证服务...
taskkill /F /FI "WINDOWTITLE eq jrxml-validator*" >nul 2>&1
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":8001.*LISTENING"') do taskkill /F /PID %%a >nul 2>&1
echo 已停止所有服务
.venv\Scripts\python.exe start.py
pause
exit /b 0
:cleanup
taskkill /F /FI "WINDOWTITLE eq jrxml-validator*" >nul 2>&1
for /f "tokens=5" %%a in ('netstat -ano ^| findstr ":8001.*LISTENING"') do taskkill /F /PID %%a >nul 2>&1
pause
exit /b 1