64 lines
2.2 KiB
Batchfile
64 lines
2.2 KiB
Batchfile
@echo off
|
|
title Stop PERLER LAB Dev Environment
|
|
setlocal enabledelayedexpansion
|
|
|
|
rem ============================================================
|
|
rem PERLER LAB stop script
|
|
rem Find processes listening on ports 5173 / 8788 via netstat
|
|
rem and terminate them with taskkill.
|
|
rem
|
|
rem Why netstat + taskkill instead of wmic:
|
|
rem - wmic is deprecated and has been removed in Windows 11 24H2+;
|
|
rem - netstat / taskkill are built-in, need no extra dependencies,
|
|
rem and can terminate ordinary user processes without admin rights.
|
|
rem
|
|
rem NOTE (BUG-087): this file is intentionally pure ASCII so it
|
|
rem parses correctly under any console codepage (including GBK).
|
|
rem ============================================================
|
|
|
|
echo Stopping PERLER LAB processes (ports 5173 / 8788)...
|
|
echo.
|
|
|
|
rem Kill the SSH DB tunnel (port 15432) - only if the process is ssh.exe,
|
|
rem so an unrelated service on that port is never touched.
|
|
for /f "tokens=5" %%A in ('netstat -ano ^| findstr ":15432 " ^| findstr "LISTENING"') do (
|
|
tasklist /fi "PID eq %%A" 2>nul | findstr /i "ssh.exe" >nul 2>nul
|
|
if not errorlevel 1 (
|
|
echo [tunnel] terminating ssh.exe PID %%A
|
|
taskkill /F /PID %%A >nul 2>nul
|
|
)
|
|
)
|
|
|
|
set "KILLED_PIDS="
|
|
set "FOUND="
|
|
|
|
rem Check the two ports in turn
|
|
for %%P in (5173 8788) do (
|
|
rem Only match LISTENING processes to avoid killing TIME_WAIT leftovers
|
|
for /f "tokens=5" %%A in ('netstat -ano ^| findstr ":%%P " ^| findstr "LISTENING"') do (
|
|
rem The same process may listen on both IPv4 and IPv6; dedupe to avoid a repeated taskkill
|
|
echo !KILLED_PIDS! | findstr /c:" %%A " >nul 2>nul
|
|
if errorlevel 1 (
|
|
set "FOUND=1"
|
|
echo [port %%P] found PID=%%A, terminating...
|
|
taskkill /F /PID %%A >nul 2>nul
|
|
if not errorlevel 1 (
|
|
echo [OK] terminated PID %%A
|
|
set "KILLED_PIDS=!KILLED_PIDS! %%A "
|
|
) else (
|
|
echo [FAIL] failed to terminate PID %%A, may need admin rights
|
|
)
|
|
)
|
|
)
|
|
)
|
|
|
|
echo.
|
|
if not defined FOUND (
|
|
echo No processes found on ports 5173 / 8788. Nothing to stop.
|
|
) else (
|
|
echo Done. PERLER LAB dev environment stopped.
|
|
)
|
|
echo.
|
|
|
|
pause
|