forked from mtusi2026/mtusi2026lab3
26 lines
793 B
Batchfile
26 lines
793 B
Batchfile
@echo off
|
|
setlocal EnableExtensions EnableDelayedExpansion
|
|
|
|
if "%TARGET_INSTANCE_ID%"=="" exit /b 2
|
|
cd /d "%~dp0\.."
|
|
|
|
set "TARGET_CONTAINER="
|
|
set /a MATCHES=0
|
|
for /f "usebackq delims=" %%C in (`docker compose --env-file .env ps -q api`) do (
|
|
set "CONTAINER_ID=%%C"
|
|
set "SHORT_ID=!CONTAINER_ID:~0,12!"
|
|
set "HOSTNAME_VALUE="
|
|
for /f "usebackq delims=" %%H in (`docker inspect --format "{{.Config.Hostname}}" %%C`) do set "HOSTNAME_VALUE=%%H"
|
|
if "!HOSTNAME_VALUE!"=="%TARGET_INSTANCE_ID%" (
|
|
set "TARGET_CONTAINER=%%C"
|
|
set /a MATCHES+=1
|
|
) else if "!SHORT_ID!"=="%TARGET_INSTANCE_ID%" (
|
|
set "TARGET_CONTAINER=%%C"
|
|
set /a MATCHES+=1
|
|
)
|
|
)
|
|
|
|
if not "!MATCHES!"=="1" exit /b 2
|
|
docker stop --time 5 "!TARGET_CONTAINER!" >nul
|
|
exit /b %ERRORLEVEL%
|