nitrokite/deployment/scripts/health-check.sh
Farid Siddiqi 7ab87de90d
All checks were successful
Build and Deploy API Server / build (push) Successful in 52s
Build and Deploy API Server / deploy (push) Successful in 4s
update build-deploy
2025-12-25 09:49:14 -08:00

41 lines
1008 B
Bash
Executable File

#!/bin/bash
set -euo pipefail
HEALTH_ENDPOINT="${HEALTH_ENDPOINT:-http://localhost:8080/hello}"
MAX_RETRIES="${MAX_RETRIES:-10}"
RETRY_DELAY="${RETRY_DELAY:-3}"
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
log_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
log_error() { echo -e "${RED}[ERROR]${NC} $1"; }
# Check if running in container (skip systemctl check)
if [ ! -f /run/systemd/system ]; then
log_info "Running in container, skipping systemd check"
else
if ! systemctl is-active --quiet api-server.service; then
log_error "Service is not running"
exit 1
fi
fi
for i in $(seq 1 $MAX_RETRIES); do
log_info "Health check attempt $i/$MAX_RETRIES..."
if response=$(curl -sf -m 5 "$HEALTH_ENDPOINT" 2>/dev/null); then
log_info "Health check passed!"
echo "$response" | head -c 200
exit 0
fi
if [ $i -lt $MAX_RETRIES ]; then
sleep $RETRY_DELAY
fi
done
log_error "Health check failed after $MAX_RETRIES attempts"
exit 1