forked from mtusi2026/mtusi2026lab4
Реализовать lab4 на оценку 4: SeaweedFS, вложения и согласованность БД/S3.
Перенесён стенд lab3 (API, Redis-сессии, идемпотентность, HAProxy, реплики API). Добавлены приватный bucket SeaweedFS с отдельным ключом API, загрузка PNG/JPEG с лимитами и полной проверкой, компенсация и reconciler, плавная остановка API, тесты и evidence.
This commit is contained in:
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
# Stop ONE API replica matching TARGET_INSTANCE_ID (= X-Instance-Id / hostname).
|
||||
# Leave it stopped; do not touch DB/Redis/LB/volumes.
|
||||
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
found=""
|
||||
# Compose project containers for service api
|
||||
ids=$(docker compose --env-file .env ps -q api 2>/dev/null || true)
|
||||
for id in $ids; do
|
||||
[ -n "$id" ] || continue
|
||||
host=$(docker inspect -f '{{.Config.Hostname}}' "$id")
|
||||
if [ "$host" = "$TARGET_INSTANCE_ID" ]; then
|
||||
found=$id
|
||||
break
|
||||
fi
|
||||
iid=$(docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' "$id" | sed -n 's/^INSTANCE_ID=//p' | head -n1)
|
||||
if [ -n "$iid" ] && [ "$iid" = "$TARGET_INSTANCE_ID" ]; then
|
||||
found=$id
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -z "$found" ]; then
|
||||
# Fallback: any running container with matching hostname (scaled names differ).
|
||||
for id in $(docker ps -q --filter "ancestor=mtusi-messenger:lab4"); do
|
||||
host=$(docker inspect -f '{{.Config.Hostname}}' "$id")
|
||||
if [ "$host" = "$TARGET_INSTANCE_ID" ]; then
|
||||
found=$id
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$found" ]; then
|
||||
printf '%s\n' "stop-one: replica not found for TARGET_INSTANCE_ID" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Graceful stop (= stop_grace_period): on SIGTERM the API reports not-ready but keeps
|
||||
# serving for a 3 s drain window, then finishes in-flight requests and exits (~3.5 s).
|
||||
docker stop -t 15 "$found" >/dev/null
|
||||
exit 0
|
||||
Reference in New Issue
Block a user