20 lines
799 B
Bash
Executable File
20 lines
799 B
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
cd "$(dirname "$0")/.."
|
|
: "${TARGET_INSTANCE_ID:?missing target alias}"
|
|
for id in $(./scripts/compose.sh ps -q api); do
|
|
current=$(docker exec "$id" wget -T 2 -qO- http://127.0.0.1:8080/internal/metrics | python3 -c 'import json,sys; print(json.load(sys.stdin)["instance_id"])')
|
|
if [ "$current" = "$TARGET_INSTANCE_ID" ]; then
|
|
docker stop --time 8 "$id" >/dev/null
|
|
python3 - "$id" "$TARGET_INSTANCE_ID" <<'PYLOG'
|
|
import json,sys,time
|
|
from pathlib import Path
|
|
with Path('evidence/failover-action.jsonl').open('a') as f:
|
|
f.write(json.dumps({'at':time.time(),'container':sys.argv[1],'instance_id':sys.argv[2],'action':'docker stop','project':'mtusi2026lab6'})+'\n')
|
|
PYLOG
|
|
exit 0
|
|
fi
|
|
done
|
|
printf '%s\n' 'Target does not match a running lab6 API process' >&2
|
|
exit 1
|