24 lines
634 B
Bash
24 lines
634 B
Bash
#!/bin/sh
|
|
set -eu
|
|
: "${TARGET_INSTANCE_ID:?}"
|
|
|
|
found=""
|
|
for id in $(docker ps -q \
|
|
--filter label=com.docker.compose.project=mtusi-lab7 \
|
|
--filter label=com.docker.compose.service=api); do
|
|
host=$(docker inspect -f '{{.Config.Hostname}}' "$id")
|
|
short=$(printf %s "$id" | cut -c1-12)
|
|
if [ "$host" = "$TARGET_INSTANCE_ID" ] || [ "$short" = "$TARGET_INSTANCE_ID" ]; then
|
|
found=$id
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ -z "$found" ]; then
|
|
echo "api replica not found" >&2
|
|
exit 1
|
|
fi
|
|
|
|
# SIGTERM, затем процесс остаётся остановленным (restart: unless-stopped).
|
|
docker stop --time 5 "$found" >/dev/null
|