forked from mtusi2026/mtusi2026lab3
Поставить несколько реплик API за общий балансировщик.
Сессия и ключ идемпотентности общие для реплик, миграция выполняется один раз, остановка одной реплики не теряет подтверждённые сообщения.
This commit is contained in:
Executable
+22
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
# Stop the API replica named by TARGET_INSTANCE_ID and leave it stopped.
|
||||
# Does not stop the database, Redis, the load balancer, or any volume.
|
||||
set -eu
|
||||
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
|
||||
ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
|
||||
cd "$ROOT"
|
||||
found=""
|
||||
for cid in $(docker compose --env-file .env ps -q api); do
|
||||
host=$(docker inspect -f '{{.Config.Hostname}}' "$cid")
|
||||
short=$(docker inspect -f '{{.Id}}' "$cid" | cut -c1-12)
|
||||
name=$(docker inspect -f '{{.Name}}' "$cid" | sed 's#^/##')
|
||||
if [ "$host" = "$TARGET_INSTANCE_ID" ] || [ "$short" = "$TARGET_INSTANCE_ID" ] || [ "$name" = "$TARGET_INSTANCE_ID" ]; then
|
||||
found=$cid
|
||||
break
|
||||
fi
|
||||
done
|
||||
if [ -z "$found" ]; then
|
||||
echo "no running api container matches the instance" >&2
|
||||
exit 1
|
||||
fi
|
||||
docker stop -t 6 "$found" >/dev/null
|
||||
Reference in New Issue
Block a user