Files
spotlightcam/scripts/health-check.sh

89 lines
2.2 KiB
Bash
Raw Normal View History

#!/bin/bash
# Health check script for spotlight.cam
# Usage: ./scripts/health-check.sh [dev|prod]
set -e
ENV=${1:-dev}
# Set service names based on environment
if [ "$ENV" = "prod" ]; then
NGINX_CONTAINER="slc-proxy-prod"
FRONTEND_CONTAINER="slc-frontend-prod"
BACKEND_CONTAINER="slc-backend-prod"
DB_CONTAINER="slc-db-prod"
API_URL="https://spotlight.cam/api/health"
else
NGINX_CONTAINER="slc-proxy"
FRONTEND_CONTAINER="slc-frontend"
BACKEND_CONTAINER="slc-backend"
DB_CONTAINER="slc-db"
API_URL="http://localhost:8080/api/health"
fi
echo "🏥 spotlight.cam Health Check"
echo "📦 Environment: $ENV"
echo "================================"
echo ""
# Function to check container status
check_container() {
local container=$1
local service=$2
if docker ps --format '{{.Names}}' | grep -q "^${container}$"; then
local status=$(docker inspect --format='{{.State.Status}}' "$container")
if [ "$status" = "running" ]; then
echo "$service: Running"
return 0
else
echo "⚠️ $service: Container exists but not running (status: $status)"
return 1
fi
else
echo "$service: Container not found"
return 1
fi
}
# Check all containers
ALL_OK=true
check_container "$NGINX_CONTAINER" "nginx" || ALL_OK=false
check_container "$FRONTEND_CONTAINER" "Frontend" || ALL_OK=false
check_container "$BACKEND_CONTAINER" "Backend" || ALL_OK=false
check_container "$DB_CONTAINER" "Database" || ALL_OK=false
echo ""
# Check API health endpoint
echo "🔌 API Health Check:"
if curl -f -s "$API_URL" > /dev/null 2>&1; then
echo "✅ API responding at $API_URL"
else
echo "❌ API not responding at $API_URL"
ALL_OK=false
fi
echo ""
# Database connection test
echo "🗄️ Database Connection:"
if docker exec "$DB_CONTAINER" pg_isready -U spotlightcam > /dev/null 2>&1; then
echo "✅ Database accepting connections"
else
echo "❌ Database not accepting connections"
ALL_OK=false
fi
echo ""
echo "================================"
if [ "$ALL_OK" = true ]; then
echo "✅ All systems operational!"
exit 0
else
echo "⚠️ Some services are not healthy"
exit 1
fi