Files
mtusi2026lab4/scripts/stop-one.sh
T

36 lines
1.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/sh
# Останавливает ровно одну API-реплику стенда — ту, которую обслужила текущая
# сессия. TARGET_INSTANCE_ID приходит из теста (значение X-Instance-Id ответа),
# а в Docker hostname контейнера равен его короткому ID, поэтому сопоставление
# однозначно. Ничего, кроме этой реплики, скрипт не трогает: ни LB, ни БД, ни
# тома. Возврат управления — быстрый (SIGTERM -> дрейн DRAIN_DELAY_MS=3s ->
# выход), останавливать реплику "навсегда" не требуется.
set -eu
: "${TARGET_INSTANCE_ID:?test provides target API instance alias}"
project="${LAB4_PROJECT:-mtusi-lab4}"
target=''
for container in $(
docker ps \
--filter "label=com.docker.compose.project=${project}" \
--filter 'label=com.docker.compose.service=api' \
--format '{{.ID}}'
); do
case "$container" in
"$TARGET_INSTANCE_ID"*)
target="$container"
break
;;
esac
done
if [ -z "$target" ]; then
printf 'stop-one: no running api replica of project %s whose id starts with %s\n' \
"$project" "$TARGET_INSTANCE_ID" >&2
exit 1
fi
printf 'stop-one: stopping api replica %s\n' "$target" >&2
docker stop --time 10 "$target" >/dev/null