forked from mtusi2026/mtusi2026lab3
ЛР 3 — БПИ2303 — Морару — на 5: API на TypeScript/Node, HAProxy, failover, трек 1
This commit is contained in:
Executable
+14
@@ -0,0 +1,14 @@
|
||||
#!/bin/sh
|
||||
# Stops exactly the API replica whose X-Instance-Id is TARGET_INSTANCE_ID and leaves it stopped.
|
||||
# X-Instance-Id = container hostname = first 12 hex chars of the container ID.
|
||||
# Restore afterwards: docker compose start api
|
||||
set -eu
|
||||
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
|
||||
cd "$(dirname "$0")/.."
|
||||
case "$TARGET_INSTANCE_ID" in
|
||||
*[!0-9a-f]* | "") echo "unexpected instance id" >&2; exit 2 ;;
|
||||
esac
|
||||
ids=$(docker compose ps -q api | grep "^$TARGET_INSTANCE_ID" || true)
|
||||
[ "$(printf '%s\n' "$ids" | grep -c .)" -eq 1 ] || { echo "no single running api container for $TARGET_INSTANCE_ID" >&2; exit 1; }
|
||||
docker stop "$ids" >/dev/null # SIGTERM -> readiness 503 -> drain -> exit (about 3 s)
|
||||
echo "stopped $(docker inspect -f '{{.Name}}' "$ids") ($TARGET_INSTANCE_ID)"
|
||||
Reference in New Issue
Block a user