Перенесите реализацию ЛР 4 на стенд ЛР 5
This commit is contained in:
Executable
+30
@@ -0,0 +1,30 @@
|
||||
#!/bin/sh
|
||||
# Lists the API containers: <id> <name> <state> <X-Instance-Id> <image>. The
|
||||
# alias is random per process, so each running replica is asked over
|
||||
# /health/live, in parallel: the failover hook must return within 10 seconds.
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
ids=$(docker compose ps -aq api)
|
||||
[ -n "$ids" ] || exit 0
|
||||
tmp=$(mktemp -d)
|
||||
trap 'rm -rf "$tmp"' EXIT
|
||||
|
||||
docker inspect --format '{{.Id}} {{.Name}} {{.State.Status}} {{.Image}}' $ids >"$tmp/containers"
|
||||
while read -r id name state image; do
|
||||
if [ "$state" = running ]; then
|
||||
# wget prints the response headers on stderr; the body is dropped.
|
||||
(docker exec "$id" wget -S -q -O - http://127.0.0.1:8080/health/live 2>&1 >/dev/null |
|
||||
sed -n 's/^ *[Xx]-[Ii]nstance-[Ii]d: *//p' | tr -d '\r' | head -n 1 >"$tmp/$id") &
|
||||
fi
|
||||
done <"$tmp/containers"
|
||||
wait
|
||||
|
||||
while read -r id name state image; do
|
||||
alias=-
|
||||
if [ -s "$tmp/$id" ]; then
|
||||
alias=$(cat "$tmp/$id")
|
||||
fi
|
||||
image=${image#sha256:}
|
||||
printf '%s %s %s %s %s\n' "$(printf '%s' "$id" | cut -c1-12)" "${name#/}" "$state" "$alias" "$(printf '%s' "$image" | cut -c1-12)"
|
||||
done <"$tmp/containers"
|
||||
Reference in New Issue
Block a user