#!/bin/bash set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR/.." wait_for_healthy() { local service=$1 local max_retries=${2:-60} local retry_count=0 local container_name echo "Waiting for $service to become healthy..." while [ "$retry_count" -lt "$max_retries" ]; do container_name=$(docker compose --profile infra --profile app ps -q "$service" 2>/dev/null | head -n1) if [ -n "$container_name" ]; then local status status=$(docker inspect --format='{{.State.Health.Status}}' "$container_name" 2>/dev/null || true) if [ "$status" = "healthy" ]; then echo "$service is healthy." return 0 fi fi retry_count=$((retry_count + 1)) sleep 2 done echo "$service did not become healthy within $((max_retries * 2)) seconds." docker compose --profile infra --profile app logs --tail=50 "$service" return 1 } echo "Starting infrastructure services..." docker compose --profile infra up -d wait_for_healthy mysql 60 wait_for_healthy redis 30 wait_for_healthy rabbitmq 60 echo "Infrastructure is ready." echo "MySQL: jdbc:mysql://localhost:3306/sino_mci" echo "Redis: localhost:6379" echo "RabbitMQ: localhost:5672 / http://localhost:15672" echo "SeaweedFS: http://localhost:9333" if [ "$1" == "--with-apps" ]; then echo "Starting application services..." # Include infra profile so that depends_on conditions can resolve. docker compose --profile infra --profile app up -d --build wait_for_healthy mci-server 90 wait_for_healthy channel-service 60 echo "Application services are ready." echo "Admin Web: http://localhost" echo "Backend API: http://localhost:8080/msg-platform" echo "Channel Service: http://localhost:8000" fi