Files
mtusi2026lab4/scripts/stop-one.bat
2026-11-05 18:08:31 +03:00

22 lines
600 B
Batchfile

@echo off
setlocal
cd /d "%~dp0.."
if "%TARGET_INSTANCE_ID%"=="" (
echo TARGET_INSTANCE_ID is required 1>&2
exit /b 2
)
set TARGET_STOPPED=
for /f "delims=" %%i in ('docker compose ps -q api') do if not defined TARGET_STOPPED call :stop_if_target %%i
if defined TARGET_STOPPED exit /b 0
echo No running API replica matches TARGET_INSTANCE_ID 1>&2
exit /b 1
:stop_if_target
for /f "delims=" %%h in ('docker inspect --format "{{.Config.Hostname}}" %1') do if "%%h"=="%TARGET_INSTANCE_ID%" (
docker stop --time 2 %1 >nul
if errorlevel 1 exit /b 1
set TARGET_STOPPED=1
exit /b 0
)
exit /b 1