Files
bakery-ia/scripts/health-check.sh
2025-07-20 02:16:51 +02:00

90 lines
2.8 KiB
Bash
Executable File

# scripts/docker-health-check.sh
#!/bin/bash
# Comprehensive health check for all services
services=(
"bakery-redis:6379"
"bakery-rabbitmq:15672"
"bakery-gateway:8000"
"bakery-auth-service:8000"
"bakery-tenant-service:8000"
"bakery-training-service:8000"
"bakery-forecasting-service:8000"
"bakery-data-service:8000"
"bakery-notification-service:8000"
)
echo "🏥 Checking service health..."
for service_port in "${services[@]}"; do
service=$(echo $service_port | cut -d: -f1)
port=$(echo $service_port | cut -d: -f2)
if docker ps --format "table {{.Names}}" | grep -q "^$service$"; then
if [ "$service" = "bakery-redis" ]; then
# Redis health check
if docker exec $service redis-cli -a redis_pass123 ping > /dev/null 2>&1; then
echo "$service is healthy"
else
echo "$service is unhealthy"
fi
elif [ "$service" = "bakery-rabbitmq" ]; then
# RabbitMQ health check
if curl -s -u bakery:forecast123 http://localhost:$port/api/health/checks/alarms > /dev/null; then
echo "$service is healthy"
else
echo "$service is unhealthy"
fi
else
# HTTP service health check
container_ip=$(docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $service)
if curl -f -s "http://$container_ip:8000/health" > /dev/null; then
echo "$service is healthy"
else
echo "$service is unhealthy"
fi
fi
else
echo "⚠️ $service is not running"
fi
done
echo ""
echo "🔍 Checking database connections..."
databases=("auth-db" "training-db" "forecasting-db" "data-db" "tenant-db" "notification-db")
for db in "${databases[@]}"; do
if docker ps --format "table {{.Names}}" | grep -q "^bakery-$db$"; then
db_name=$(echo $db | sed 's/-/_/g')
user=$(echo $db | sed 's/-db//' | sed 's/-/_/g')_user
if docker exec bakery-$db pg_isready -U $user -d $db_name > /dev/null 2>&1; then
echo "✅ bakery-$db is ready"
else
echo "❌ bakery-$db is not ready"
fi
else
echo "⚠️ bakery-$db is not running"
fi
done
echo ""
echo "📊 Service resource usage:"
docker stats --no-stream --format "table {{.Container}}\t{{.CPUPerc}}\t{{.MemUsage}}" $(docker ps --format "{{.Names}}" | grep "^bakery-")
# scripts/docker-logs.sh
#!/bin/bash
# View logs for specific service or all services
SERVICE=${1:-"all"}
if [ "$SERVICE" = "all" ]; then
echo "📋 Showing logs for all services..."
docker-compose logs -f --tail=100
else
echo "📋 Showing logs for $SERVICE..."
docker-compose logs -f --tail=100 $SERVICE
fi