Files
bakery-ia/scripts/restart-service.sh

106 lines
2.5 KiB
Bash
Raw Normal View History

2025-07-20 02:16:51 +02:00
# ================================================================
# SERVICE RESTART SCRIPT
# scripts/restart-service.sh
# ================================================================
#!/bin/bash
# Restart individual service script
set -e
GREEN='\033[0;32m'
BLUE='\033[0;34m'
RED='\033[0;31m'
NC='\033[0m'
print_step() {
echo -e "${BLUE}[RESTART]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
restart_service() {
local service=$1
print_step "Restarting $service..."
# Build the service
docker-compose build $service
# Restart with zero downtime
docker-compose up -d --no-deps --force-recreate $service
# Wait a bit for the service to start
sleep 5
# Check health
local port
case $service in
"gateway") port=8000 ;;
"auth-service") port=8001 ;;
"training-service") port=8002 ;;
"forecasting-service") port=8003 ;;
"data-service") port=8004 ;;
"tenant-service") port=8005 ;;
"notification-service") port=8006 ;;
*)
print_error "Unknown service: $service"
exit 1
;;
esac
# Health check with timeout
local attempts=0
local max_attempts=12 # 60 seconds total
while [ $attempts -lt $max_attempts ]; do
if curl -f -s "http://localhost:$port/health" > /dev/null 2>&1; then
print_success "$service is healthy and ready"
return 0
fi
attempts=$((attempts + 1))
echo "Waiting for $service to be healthy... ($attempts/$max_attempts)"
sleep 5
done
print_error "$service failed to become healthy within 60 seconds"
return 1
}
# Main function
main() {
if [ $# -eq 0 ]; then
echo "Usage: $0 <service-name>"
echo ""
echo "Available services:"
echo " gateway"
echo " auth-service"
echo " training-service"
echo " forecasting-service"
echo " data-service"
echo " tenant-service"
echo " notification-service"
echo ""
echo "Example: $0 auth-service"
exit 1
fi
local service=$1
echo "================================================================"
echo "RESTARTING SERVICE: $service"
echo "================================================================"
restart_service $service
}
# Run main function
main "$@"