forked from mtusi2026/mtusi2026lab3
23 lines
621 B
Bash
23 lines
621 B
Bash
#!/bin/sh
|
|
set -eu
|
|
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
|
|
cd "$(dirname "$0")/.."
|
|
|
|
found=""
|
|
for cid in $(docker compose --env-file .env -f compose.yaml ps -q api); do
|
|
host=$(docker inspect -f '{{.Config.Hostname}}' "$cid")
|
|
short=$(printf '%s' "$cid" | cut -c1-12)
|
|
if [ "$host" = "$TARGET_INSTANCE_ID" ] || [ "$short" = "$TARGET_INSTANCE_ID" ]; then
|
|
found=$cid
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$found" ]; then
|
|
echo "API replica was not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# docker stop + restart: unless-stopped оставляет реплику выключенной.
|
|
docker stop -t 8 "$found" >/dev/null
|