This commit is contained in:
2026-10-23 19:30:08 +03:00
parent 0ab3a341aa
commit 7e0595d211
26 changed files with 1237 additions and 1 deletions
Executable → Regular
View File
+17
View File
@@ -0,0 +1,17 @@
@echo off
if "%TARGET_INSTANCE_ID%"=="" (
echo TARGET_INSTANCE_ID is not set
exit /b 1
)
for /f "tokens=*" %%i in ('docker ps -q --filter "name=lab3-api"') do (
for /f "tokens=*" %%h in ('docker inspect -f "{{.Config.Hostname}}" %%i') do (
if "%%h"=="%TARGET_INSTANCE_ID%" (
echo Stopping container %%i
docker stop %%i
exit /b 0
)
)
)
echo Container not found
exit /b 1
Executable → Regular
View File
+30
View File
@@ -0,0 +1,30 @@
#!/bin/sh
# Скрипт останавливает конкретную реплику API по её X-Instance-Id.
set -eu
if [ -z "${TARGET_INSTANCE_ID:-}" ]; then
echo "TARGET_INSTANCE_ID is not set" >&2
exit 1
fi
# Так как INSTANCE_ID = socket.gethostname(), в Docker это короткий ID контейнера.
cid=$(docker ps -q --filter "id=$TARGET_INSTANCE_ID" || true)
if [ -z "$cid" ]; then
# Если по ID не нашли, ищем по имени проекта и проверяем hostname
for c in $(docker ps -q --filter "name=lab3-api"); do
h=$(docker inspect -f '{{.Config.Hostname}}' "$c")
if [ "$h" = "$TARGET_INSTANCE_ID" ]; then
cid="$c"
break
fi
done
fi
if [ -n "$cid" ]; then
echo "Stopping container $cid (Instance ID: $TARGET_INSTANCE_ID)"
docker stop "$cid"
else
echo "Container with instance ID $TARGET_INSTANCE_ID not found" >&2
exit 1
fi