23 lines
1.2 KiB
Batchfile
23 lines
1.2 KiB
Batchfile
@echo off
|
|
rem Restart backend: kill old process tree on port 8000, then start uvicorn with --reload.
|
|
rem Log goes to repo root backend_run.log. Usage: cmd /c backend\restart_backend.cmd
|
|
rem NOTE: keep this file ASCII only (cmd.exe reads it as GBK, UTF-8 Chinese breaks parsing).
|
|
cd /d "%~dp0"
|
|
|
|
rem uvicorn --reload spawns launcher -> reloader -> worker, and the reloader holds the :8000
|
|
rem socket. Killing the listener with /T tears down its worker child too, and the launcher
|
|
rem exits on its own once its child is gone -- so no orphan survives. (Git Bash: restart_backend.sh)
|
|
for /f "tokens=5" %%a in ('netstat -ano ^| findstr /r /c:":8000 .*LISTENING"') do (
|
|
echo kill old PID %%a
|
|
taskkill /PID %%a /T /F >nul 2>&1
|
|
)
|
|
rem sleep ~2s (GNU timeout from Git Bash PATH shadows cmd timeout, use ping instead)
|
|
ping -n 3 127.0.0.1 >nul
|
|
|
|
rem Clear SSLKEYLOGFILE (has U+202A control chars that crash asyncpg, same as env -u)
|
|
set "SSLKEYLOGFILE="
|
|
|
|
rem redirect must live inside cmd /c - a redirect on the start line is not inherited by the child
|
|
start "stock-backend" /min cmd /c ".venv\Scripts\python.exe -m uvicorn app.main:app --reload --port 8000 > ..\backend_run.log 2>&1"
|
|
echo backend restarting, log: backend_run.log
|