#!/bin/bash # CHORUS Services Management Script # Unified management interface for all CHORUS Services components set -e SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" cd "$SCRIPT_DIR" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Print colored output print_info() { echo -e "${BLUE}[INFO]${NC} $1" } print_success() { echo -e "${GREEN}[SUCCESS]${NC} $1" } print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1" } print_error() { echo -e "${RED}[ERROR]${NC} $1" } # Show usage information show_usage() { echo "CHORUS Services Management Script" echo "" echo "Usage: $0 [COMMAND]" echo "" echo "Commands:" echo " start Start all CHORUS Services" echo " stop Stop all CHORUS Services" echo " restart Restart all CHORUS Services" echo " status Show status of all services" echo " logs Show logs from all services" echo " logs [service] Show logs from specific service" echo " build Build and push all docker images to registry" echo " pull Pull latest images from registry" echo " update Update all submodules to latest" echo " init Initialize submodules (first time setup)" echo " clean Clean up docker resources" echo " health Check health of all services" echo " login Login to Docker registry" echo " deploy Deploy to Docker Swarm (production)" echo " undeploy Remove from Docker Swarm" echo " dev Start in development mode with local builds" echo "" echo "Services:" echo " - whoosh-backend : Orchestration API (port 8087)" echo " - whoosh-frontend : Web Dashboard (port 3001)" echo " - bzzz-coordinator : P2P Coordination (port 8080)" echo " - slurp-api : Context Management (port 8088)" echo " - slurp-rl-tuner : RL Context Tuner (port 8089)" echo " - postgres : Database (port 5433)" echo " - redis : Cache (port 6380)" echo " - prometheus : Metrics (port 9091)" echo " - grafana : Monitoring (port 3002)" } # Initialize git submodules init_submodules() { print_info "Initializing git submodules..." git submodule init git submodule update --recursive print_success "Submodules initialized" } # Update git submodules update_submodules() { print_info "Updating git submodules..." git submodule update --remote --recursive print_success "Submodules updated" } # Build and push all docker images build_images() { print_info "Building and pushing CHORUS Services docker images to registry..." ./build-and-push.sh print_success "All images built and pushed successfully" } # Pull latest images from registry pull_images() { print_info "Pulling latest CHORUS Services images from registry..." docker-compose pull print_success "All images pulled successfully" } # Login to Docker registry docker_login() { print_info "Logging into Docker registry..." ./build-and-push.sh login } # Start all services start_services() { print_info "Starting CHORUS Services..." docker-compose up -d print_info "Waiting for services to start..." sleep 10 print_success "CHORUS Services started" print_info "Access points:" echo " - WHOOSH Dashboard: http://localhost:3001" echo " - WHOOSH API: http://localhost:8087" echo " - BZZZ Coordinator: http://localhost:8080" echo " - SLURP API: http://localhost:8088" echo " - SLURP RL Tuner: http://localhost:8089" echo " - Grafana: http://localhost:3002 (admin/chorusadmin)" echo " - Prometheus: http://localhost:9092" } # Start in development mode start_dev() { print_info "Starting CHORUS Services in development mode..." docker-compose -f docker-compose.yml -f docker-compose.dev.yml up -d --build print_info "Waiting for services to start..." sleep 15 print_success "CHORUS Services started in development mode" print_info "Development features enabled:" echo " - Live code reloading" echo " - Debug logging enabled" echo " - Local builds (no registry required)" } # Deploy to Docker Swarm deploy_swarm() { print_info "Deploying CHORUS Services to Docker Swarm..." # Check if we're in a swarm if ! docker info --format '{{.Swarm.LocalNodeState}}' | grep -q active; then print_error "Docker Swarm is not active. Please initialize or join a swarm first." return 1 fi docker stack deploy -c docker-compose.swarm.yml chorus print_info "Waiting for stack to deploy..." sleep 20 print_success "CHORUS Services deployed to swarm" print_info "Production access points:" echo " - WHOOSH Dashboard: https://chorus.home.deepblack.cloud" echo " - WHOOSH API: https://chorus-api.home.deepblack.cloud" echo " - BZZZ Coordinator: https://chorus-bzzz.home.deepblack.cloud" echo " - SLURP API: https://chorus-slurp.home.deepblack.cloud" echo " - COOEE RL Tuner: https://chorus-cooee.home.deepblack.cloud" echo " - Grafana: https://chorus-grafana.home.deepblack.cloud" echo " - Prometheus: https://chorus-prometheus.home.deepblack.cloud" } # Remove from Docker Swarm undeploy_swarm() { print_info "Removing CHORUS Services from Docker Swarm..." docker stack rm chorus print_success "CHORUS Services removed from swarm" } # Stop all services stop_services() { print_info "Stopping CHORUS Services..." docker-compose down print_success "CHORUS Services stopped" } # Restart all services restart_services() { print_info "Restarting CHORUS Services..." stop_services start_services } # Show service status show_status() { print_info "CHORUS Services Status:" docker-compose ps } # Show logs show_logs() { if [ -z "$1" ]; then print_info "Showing logs from all services..." docker-compose logs -f else print_info "Showing logs from $1..." docker-compose logs -f "$1" fi } # Check health of services check_health() { print_info "Checking CHORUS Services health..." services=( "http://localhost:8087/health|WHOOSH Backend" "http://localhost:3001|WHOOSH Frontend" "http://localhost:8080/health|BZZZ Coordinator" "http://localhost:8088/health|SLURP API" "http://localhost:8089/health|SLURP RL Tuner" "http://localhost:9092/-/healthy|Prometheus" "http://localhost:3002/api/health|Grafana" ) for service in "${services[@]}"; do url=$(echo "$service" | cut -d'|' -f1) name=$(echo "$service" | cut -d'|' -f2) if curl -s -f "$url" > /dev/null 2>&1; then print_success "$name is healthy" else print_error "$name is not responding" fi done } # Clean up docker resources clean_resources() { print_warning "This will remove all CHORUS Services containers, networks, and volumes" read -p "Are you sure? (y/N): " -n 1 -r echo if [[ $REPLY =~ ^[Yy]$ ]]; then print_info "Cleaning up docker resources..." docker-compose down -v --remove-orphans docker system prune -f print_success "Cleanup completed" else print_info "Cleanup cancelled" fi } # Main command handler case "$1" in start) start_services ;; stop) stop_services ;; restart) restart_services ;; status) show_status ;; logs) show_logs "$2" ;; build) build_images ;; pull) pull_images ;; update) update_submodules ;; init) init_submodules ;; clean) clean_resources ;; health) check_health ;; login) docker_login ;; deploy) deploy_swarm ;; undeploy) undeploy_swarm ;; dev) start_dev ;; *) show_usage exit 1 ;; esac