#!/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"; } if ! systemctl is-active --quiet api-server.service; then log_error "Service is not running" exit 1 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