This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
#!/bin/sh
|
||||
# Останавливает ровно одну API-реплику по X-Instance-Id (= hostname контейнера)
|
||||
# и оставляет её остановленной. Восстановление — scripts/restore.sh.
|
||||
set -eu
|
||||
project=${COMPOSE_PROJECT_NAME:-lab7}
|
||||
target=${TARGET_INSTANCE_ID:-}
|
||||
if [ -z "$target" ]; then
|
||||
printf 'TARGET_INSTANCE_ID is required\n' >&2
|
||||
exit 2
|
||||
fi
|
||||
for container in $(docker ps -q \
|
||||
--filter "label=com.docker.compose.project=$project" \
|
||||
--filter "label=com.docker.compose.service=api"); do
|
||||
hostname=$(docker inspect -f '{{.Config.Hostname}}' "$container" 2>/dev/null || true)
|
||||
if [ "$hostname" = "$target" ]; then
|
||||
printf 'stopping instance %s container %s\n' "$target" "$container"
|
||||
docker stop --time 3 "$container" >/dev/null
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
printf 'target instance %s not found among running api containers\n' "$target" >&2
|
||||
exit 4
|
||||
Reference in New Issue
Block a user