Files
mtusi2026lab4/scripts/stop-one.bat
2026-10-26 16:10:22 +03:00

28 lines
748 B
Batchfile

@echo off
setlocal EnableDelayedExpansion
cd /d "%~dp0.."
if "%TARGET_INSTANCE_ID%"=="" (
echo FAIL: TARGET_INSTANCE_ID is not set
exit /b 1
)
for /f "tokens=1 delims=-" %%a in ("%TARGET_INSTANCE_ID%") do set PREFIX=%%a
echo Target instance: %TARGET_INSTANCE_ID%
echo Hostname prefix: %PREFIX%
for /f "delims=" %%i in ('docker ps --filter "label=com.docker.compose.service=api" --format "{{.ID}}"') do (
for /f "delims=" %%h in ('docker inspect --format "{{.Config.Hostname}}" %%i') do (
set "H=%%h"
echo !H! | findstr /b /c:"%PREFIX%" >nul
if not errorlevel 1 (
echo Stopping container %%i with hostname !H!
docker stop --time 10 %%i >nul
exit /b 0
)
)
)
echo FAIL: target replica not found
exit /b 1