Files
spotlightcam/scripts/health-check.sh
Radosław Gierwiało 642c8f6d6f feat: add production operations scripts and monitoring guide
Add comprehensive tooling for production deployment:

Scripts (scripts/):
- backup-db.sh: Automated database backups with 7-day retention
- restore-db.sh: Safe database restore with confirmation prompts
- health-check.sh: Complete service health monitoring
- README.md: Operational scripts documentation

Monitoring (docs/MONITORING.md):
- Application health monitoring
- Docker container monitoring
- External monitoring setup (UptimeRobot, Pingdom)
- Log monitoring and rotation
- Alerting configuration
- Incident response procedures
- SLA targets and metrics

All scripts include:
- Environment support (dev/prod)
- Error handling and validation
- Detailed status reporting
- Safety confirmations where needed
2025-11-20 22:22:22 +01:00

89 lines
2.2 KiB
Bash

#!/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