Files
mtusi2026lab3/scripts/stop-one.sh
T

21 lines
902 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
if [ "${VP_RUNTIME:-k3s}" = k3s ]; then exec bun --no-env-file scripts/k3s.ts stop-one; fi
: "${TARGET_INSTANCE_ID:?public resilience test must provide target instance}"
[[ "$TARGET_INSTANCE_ID" =~ ^[a-zA-Z0-9._-]+$ ]]
ids=(); while IFS= read -r id; do ids+=("$id"); done < <(./scripts/compose.sh ps -q api)
test "${#ids[@]}" -ge 2
for id in "${ids[@]}"; do
hostname=$(docker inspect --format '{{.Config.Hostname}}' "$id")
if [ "$hostname" = "$TARGET_INSTANCE_ID" ]; then
mkdir -p evidence
docker inspect --format '{{.Name}} {{.Id}} {{.State.Running}}' "$id" >evidence/stop-one-before.txt
docker stop --time 8 "$id" >/dev/null
docker inspect --format '{{.Name}} {{.Id}} {{.State.Running}}' "$id" >evidence/stop-one-after.txt
exit 0
fi
done
echo 'Target is not a running replica in this Compose project' >&2
exit 1