VaultTest/vault-check-health.sh
Murat ÖZDEMİR 99af68deb2 feat(vault): Add cluster health check to skip bootstrap
Integrates `vault-check-health.sh` into `vault-bootstrap.sh` to perform a network-based health check. If all Vault nodes are found initialized and unsealed, the bootstrap process is skipped, preventing unnecessary restarts or re-initialization.

Renames `failover_scenarios.md` to `vault_failover_scenarios.md` for improved clarity and consistency.
2026-06-12 09:42:10 +03:00

35 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# vault-check-health.sh — Verifies cluster health over the network (no token required).
# Returns 0 (success) if all 3 nodes are initialized and unsealed.
VAULT_NODES=("vault-1.iklim.co" "vault-2.iklim.co" "vault-3.iklim.co")
HEALTHY_COUNT=0
echo " --> Starting cluster health check (network-based)..."
for node in "${VAULT_NODES[@]}"; do
# Check the /v1/sys/health endpoint for each node.
# 200: Initialized, unsealed, active
# 429: Initialized, unsealed, standby
# 501: Not initialized
# 503: Sealed
status_code=$(docker run --rm --network iklimco-net alpine/curl -s -o /dev/null -w "%{http_code}" \
--max-time 3 -k "https://${node}:8200/v1/sys/health" || echo "000")
if [ "$status_code" = "200" ] || [ "$status_code" = "429" ]; then
echo " [✓] $node: Healthy (Status: $status_code)"
HEALTHY_COUNT=$((HEALTHY_COUNT + 1))
else
echo " [!] $node: Problematic or Not Responding (Status: $status_code)"
fi
done
if [ "$HEALTHY_COUNT" -eq 3 ]; then
echo " --> Result: All nodes (3/3) are healthy."
exit 0
else
echo " --> Result: Cluster is not fully healthy ($HEALTHY_COUNT/3)."
exit 1
fi