Files
mtusi2026lab3/scripts/stop-one.sh
T
PoRATL e0e1a1e6c1 Добавить балансировку и идемпотентность для лабораторной 3.
Две реплики API за HAProxy, общий PostgreSQL и повтор сообщения без дубля.
2026-11-13 07:30:46 +00:00

16 lines
479 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
: "${TARGET_INSTANCE_ID:?}"
found=0
for id in $(docker compose --env-file .env ps -q api); do
docker exec "$id" curl -fsS -o /dev/null -D /tmp/live-headers.txt http://127.0.0.1:8080/health/live || true
got=$(docker exec "$id" grep -i "^x-instance-id:" /tmp/live-headers.txt | awk "{print \$2}" | tr -d "\r")
if [ "$got" = "$TARGET_INSTANCE_ID" ]; then
docker stop -t 5 "$id"
found=1
break
fi
done
test "$found" -eq 1