forked from mtusi2026/mtusi2026lab3
28 lines
819 B
Bash
28 lines
819 B
Bash
#!/bin/sh
|
|
set -eu
|
|
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
|
|
ROOT=$(CDPATH= cd -- "$(dirname "$0")/.." && pwd)
|
|
cd "$ROOT"
|
|
found=""
|
|
for id in $(docker compose ps -aq -- api); do
|
|
hostname=$(docker inspect -f '{{.Config.Hostname}}' "$id")
|
|
name=$(docker inspect -f '{{.Name}}' "$id")
|
|
name=${name#/}
|
|
cid=$(docker inspect -f '{{.Id}}' "$id")
|
|
short=$(printf '%s' "$cid" | cut -c1-12)
|
|
if [ "$TARGET_INSTANCE_ID" = "$hostname" ] \
|
|
|| [ "$TARGET_INSTANCE_ID" = "$name" ] \
|
|
|| [ "$TARGET_INSTANCE_ID" = "$id" ] \
|
|
|| [ "$TARGET_INSTANCE_ID" = "$cid" ] \
|
|
|| [ "$TARGET_INSTANCE_ID" = "$short" ]; then
|
|
found=$id
|
|
break
|
|
fi
|
|
done
|
|
if [ -z "$found" ]; then
|
|
printf '%s\n' "no API replica matches TARGET_INSTANCE_ID" >&2
|
|
exit 1
|
|
fi
|
|
docker stop -t 5 "$found" >/dev/null
|
|
exit 0
|