Files
mtusi2026lab5/scripts/stop-one.sh
T

28 lines
647 B
Bash

#!/bin/sh
set -eu
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
TARGET=""
for c in $(docker ps --filter "label=com.docker.compose.service=api" -q); do
id=$(docker exec "$c" cat /tmp/instance_id 2>/dev/null || true)
if [ "$id" = "$TARGET_INSTANCE_ID" ]; then
TARGET="$c"
break
fi
done
if [ -z "$TARGET" ]; then
echo "no api replica with INSTANCE_ID=$TARGET_INSTANCE_ID" >&2
exit 1
fi
docker stop -t 3 "$TARGET" >/dev/null
i=0
while [ $i -lt 50 ]; do
if ! docker ps --filter "id=$TARGET" --format "{{.ID}}" | grep -q .; then
exit 0
fi
i=$((i+1)); sleep 0.1
done
exit 0