Files
mtusi2026lab4/scripts/stop-one.sh
T
Mlvn 7cbb75c897 Реализовать lab4: вложения S3/MinIO, уровень 4 и трек 2 reconciler.
Метаданные в PostgreSQL, байты в приватном bucket; sync upload 201 ready;
компенсация orphan и cmd/reconcile с dry-run/apply и grace period.
2026-11-12 18:08:47 +03:00

45 lines
1.6 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Останавливает РОВНО одну API-реплику, чей X-Instance-Id = TARGET_INSTANCE_ID.
# Реплика остаётся остановленной; восстановление — scripts/restore-one.sh или compose up.
# Не трогает postgres/redis/lb/volumes. Должен завершиться за <10 с.
set -eu
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
cd "$ROOT"
ids=$(docker compose --env-file .env ps -q api)
if [ -z "$ids" ]; then
echo "no api containers" >&2
exit 1
fi
found=0
for id in $ids; do
# Совпадает с config.InstanceID: hostname контейнера, если INSTANCE_ID не задан.
hostname=$(docker inspect -f '{{.Config.Hostname}}' "$id")
env_id=$(docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' "$id" | sed -n 's/^INSTANCE_ID=//p' | head -n1)
match=$hostname
if [ -n "$env_id" ]; then
match=$env_id
fi
if [ "$match" = "$TARGET_INSTANCE_ID" ]; then
# Явный stop контейнера; restart: "no" у api гарантирует, что он не вернётся сам.
docker stop -t 8 "$id" >/dev/null
# Подтверждаем, что контейнер действительно не running — иначе failover-тест врёт.
state=$(docker inspect -f '{{.State.Running}}' "$id")
if [ "$state" = "true" ]; then
echo "container still running after stop" >&2
exit 1
fi
found=1
break
fi
done
if [ "$found" -ne 1 ]; then
echo "TARGET_INSTANCE_ID not found among api replicas" >&2
exit 1
fi
exit 0