Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
141 lines
3.9 KiB
Bash
Executable File
141 lines
3.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Script to wait for all services to be ready
|
|
set -e
|
|
|
|
# Color codes for output
|
|
RED='\033[0;31m'
|
|
GREEN='\033[0;32m'
|
|
YELLOW='\033[1;33m'
|
|
BLUE='\033[0;34m'
|
|
NC='\033[0m' # No Color
|
|
|
|
# Function to print colored output
|
|
print_status() {
|
|
echo -e "${GREEN}[WAIT]${NC} $1"
|
|
}
|
|
|
|
print_error() {
|
|
echo -e "${RED}[ERROR]${NC} $1"
|
|
}
|
|
|
|
print_warning() {
|
|
echo -e "${YELLOW}[WARNING]${NC} $1"
|
|
}
|
|
|
|
print_info() {
|
|
echo -e "${BLUE}[INFO]${NC} $1"
|
|
}
|
|
|
|
# Default timeout
|
|
TIMEOUT=${TIMEOUT:-300} # 5 minutes default
|
|
START_TIME=$(date +%s)
|
|
|
|
# Function to check if timeout has been exceeded
|
|
check_timeout() {
|
|
local current_time=$(date +%s)
|
|
local elapsed=$((current_time - START_TIME))
|
|
|
|
if [ $elapsed -gt $TIMEOUT ]; then
|
|
print_error "Timeout exceeded ($TIMEOUT seconds)"
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Function to wait for a service to be healthy
|
|
wait_for_service() {
|
|
local service_name=$1
|
|
local check_command=$2
|
|
local max_attempts=60
|
|
local attempt=0
|
|
|
|
print_status "Waiting for $service_name to be ready..."
|
|
|
|
while [ $attempt -lt $max_attempts ]; do
|
|
check_timeout
|
|
|
|
if eval "$check_command" &> /dev/null; then
|
|
print_status "✓ $service_name is ready"
|
|
return 0
|
|
fi
|
|
|
|
attempt=$((attempt + 1))
|
|
sleep 5
|
|
done
|
|
|
|
print_error "$service_name failed to become ready"
|
|
return 1
|
|
}
|
|
|
|
# Function to wait for HTTP endpoint
|
|
wait_for_http() {
|
|
local service_name=$1
|
|
local url=$2
|
|
local max_attempts=60
|
|
local attempt=0
|
|
|
|
print_status "Waiting for $service_name HTTP endpoint to be ready..."
|
|
|
|
while [ $attempt -lt $max_attempts ]; do
|
|
check_timeout
|
|
|
|
if curl -s -o /dev/null -w "%{http_code}" "$url" | grep -q "200"; then
|
|
print_status "✓ $service_name HTTP endpoint is ready"
|
|
return 0
|
|
fi
|
|
|
|
attempt=$((attempt + 1))
|
|
sleep 5
|
|
done
|
|
|
|
print_error "$service_name HTTP endpoint failed to become ready"
|
|
return 1
|
|
}
|
|
|
|
# Main execution
|
|
print_info "Waiting for services to be ready (timeout: ${TIMEOUT}s)..."
|
|
|
|
# Wait for databases
|
|
wait_for_service "MongoDB" "docker exec marketing_mongodb mongosh --eval 'db.adminCommand({ping: 1})' --quiet"
|
|
wait_for_service "Redis" "docker exec marketing_redis redis-cli -a \${REDIS_PASSWORD} ping"
|
|
wait_for_service "RabbitMQ" "docker exec marketing_rabbitmq rabbitmq-diagnostics -q ping"
|
|
|
|
# Wait for Elasticsearch (optional)
|
|
if docker ps | grep -q marketing_elasticsearch; then
|
|
wait_for_service "Elasticsearch" "curl -s -u elastic:\${ELASTIC_PASSWORD} http://localhost:9201/_cluster/health"
|
|
fi
|
|
|
|
# Wait for core services
|
|
wait_for_http "API Gateway" "http://localhost:3030/health"
|
|
wait_for_http "Orchestrator" "http://localhost:3030/api/orchestrator/health"
|
|
wait_for_http "Claude Agent" "http://localhost:3030/api/claude/health"
|
|
wait_for_http "GramJS Adapter" "http://localhost:3030/api/telegram/health"
|
|
wait_for_http "Safety Guard" "http://localhost:3030/api/safety/health"
|
|
wait_for_http "Analytics" "http://localhost:3030/api/analytics/health"
|
|
|
|
# Wait for optional services
|
|
services=("compliance" "ab-testing" "workflow" "webhook" "template" "i18n" "user-management" "scheduler" "logging")
|
|
|
|
for service in "${services[@]}"; do
|
|
if docker ps | grep -q "marketing_${service}"; then
|
|
wait_for_http "${service^}" "http://localhost:3030/api/${service}/health" || print_warning "${service^} service not responding (non-critical)"
|
|
fi
|
|
done
|
|
|
|
# Calculate total time
|
|
END_TIME=$(date +%s)
|
|
TOTAL_TIME=$((END_TIME - START_TIME))
|
|
|
|
print_status "All services are ready! (took ${TOTAL_TIME}s)"
|
|
|
|
# Show service status
|
|
print_info "Service Status:"
|
|
docker compose ps
|
|
|
|
# Show URLs
|
|
echo ""
|
|
print_info "Service URLs:"
|
|
print_info "- API Gateway: http://localhost:3030"
|
|
print_info "- Frontend: http://localhost:3008"
|
|
print_info "- Grafana: http://localhost:3032 (admin/admin)"
|
|
print_info "- RabbitMQ: http://localhost:15673 (admin/admin)" |