Files
aza/AzA march 2026 - Kopie (9)/start_backend_autoport.bat

53 lines
1.5 KiB
Batchfile
Raw Permalink Normal View History

2026-04-16 13:32:32 +02:00
@echo off
setlocal EnableExtensions
cd /d "%~dp0"
set "BACKEND_URL=http://127.0.0.1:8000"
set "BACKEND_HEALTH=%BACKEND_URL%/health"
set "READY_TIMEOUT_SEC=45"
set "TOKENFILE=%~dp0backend_token.txt"
REM ---- kill any python using port 8000 (simple & robust)
for /f "tokens=5" %%P in ('netstat -ano ^| findstr :8000') do taskkill /F /PID %%P >nul 2>&1
REM ---- ensure logs folder
if not exist logs mkdir logs
REM ---- ensure backend token for API auth
if not exist "%TOKENFILE%" (
echo dev-secret-2026> "%TOKENFILE%"
)
set "BACKEND_TOKEN="
set /p BACKEND_TOKEN=<"%TOKENFILE%"
if "%BACKEND_TOKEN%"=="" set "BACKEND_TOKEN=dev-secret-2026"
REM ---- start backend in background
start "" /B cmd /c "set MEDWORK_API_TOKEN=%BACKEND_TOKEN%&& python backend_main.py 1>logs\backend.log 2>&1"
REM ---- wait until backend is really reachable
python "%~dp0tools\wait_http_ready.py" "%BACKEND_HEALTH%" %READY_TIMEOUT_SEC% >nul 2>&1
if errorlevel 1 goto backend_timeout
goto backend_ready
:backend_timeout
echo FEHLER: Backend nicht erreichbar nach %READY_TIMEOUT_SEC%s (^%BACKEND_HEALTH%^)
echo Siehe Logs: logs\backend.log
endlocal
exit /b 2
:backend_ready
REM ---- write backend url (Variante-B-Schutz: nicht ueberschreiben wenn Live-Backend)
if not exist "%~dp0backend_url.txt" goto write_backend_url
findstr /i "api.aza-medwork" "%~dp0backend_url.txt" >nul 2>&1
if not errorlevel 1 (
echo HINWEIS: backend_url.txt zeigt auf Live-Backend, wird NICHT ueberschrieben.
goto skip_backend_url
)
:write_backend_url
echo %BACKEND_URL%> backend_url.txt
:skip_backend_url
endlocal
exit /b 0