gaza/scripts/check-web-health.sh
Ubuntu 6e422f6e41 补齐持续集成与 Docker 健康验证
Co-authored-by: multica-agent <github@multica.ai>
2026-08-03 19:06:05 +00:00

33 lines
782 B
Bash
Executable File
Raw Permalink 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
set -eu
max_attempts="${WEB_HEALTH_ATTEMPTS:-30}"
attempt=1
while [ "$attempt" -le "$max_attempts" ]; do
container_id="$(docker compose ps --quiet web)"
if [ -z "$container_id" ]; then
echo "Web 容器未运行" >&2
exit 1
fi
status="$(docker inspect --format '{{if .State.Health}}{{.State.Health.Status}}{{else}}missing{{end}}' "$container_id")"
case "$status" in
healthy)
echo "Web 容器健康检查通过"
exit 0
;;
unhealthy|missing)
echo "Web 容器健康状态异常:$status" >&2
exit 1
;;
esac
echo "等待 Web 容器健康检查($attempt/$max_attempts,当前:$status"
attempt=$((attempt + 1))
sleep 2
done
echo "Web 容器未在预期时间内进入 healthy 状态" >&2
exit 1