forked from mtusi2026/mtusi2026lab3
Provide resource profiles, persistent storage, parallel Nginx health checks and graceful restart hooks.
25 lines
626 B
Bash
Executable File
25 lines
626 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
project_dir=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
cd "$project_dir"
|
|
|
|
target=${TARGET_INSTANCE_ID:?test provides target API instance ID}
|
|
|
|
containers=$(docker compose ps --all --quiet api)
|
|
if [ -z "$containers" ]; then
|
|
printf 'No API containers found\n' >&2
|
|
exit 2
|
|
fi
|
|
for entry in $(docker inspect --format '{{.Config.Hostname}}:{{.Id}}' $containers); do
|
|
instance=${entry%%:*}
|
|
container=${entry#*:}
|
|
if [ "$instance" = "$target" ]; then
|
|
docker stop --time 30 "$container" >/dev/null
|
|
exit 0
|
|
fi
|
|
done
|
|
|
|
printf 'No API container matches X-Instance-Id\n' >&2
|
|
exit 2
|