Files
mtusi2026lab3/scripts/stop-one.sh
T
2026-11-07 10:41:21 +03:00

18 lines
688 B
Bash
Executable File

#!/bin/sh
set -eu
cd "$(dirname "$0")/.."
: "${TARGET_INSTANCE_ID:?missing target alias}"
for id in $(./scripts/compose.sh ps -q api); do
hostname=$(docker inspect --format '{{.Config.Hostname}}' "$id")
case "$TARGET_INSTANCE_ID" in
"$hostname"-*)
current=$(docker exec "$id" wget -T 2 -qO- http://127.0.0.1:8080/internal/metrics | python3 -c 'import json,sys; print(json.load(sys.stdin)["instance_id"])')
[ "$current" = "$TARGET_INSTANCE_ID" ] || { printf '%s\n' 'Target process was already replaced' >&2; exit 1; }
docker stop --time 8 "$id" >/dev/null
exit 0 ;;
esac
done
printf '%s\n' 'Target does not match a running lab3 API container' >&2
exit 1