#!/bin/bash set -e # Funzione per attendere servizio wait_for_service() { local host=$1 local port=$2 local max_attempts=30 local attempt=0 echo "Waiting for $host:$port..." while ! nc -z "$host" "$port" 2>/dev/null; do attempt=$((attempt + 1)) if [ $attempt -ge $max_attempts ]; then echo "ERROR: Service $host:$port not available after $max_attempts attempts" return 1 fi echo "Attempt $attempt/$max_attempts..." sleep 2 done echo "$host:$port is available!" } # Funzione per avviare FastAPI server start_api_server() { echo "Starting FastAPI documentation server on port 8000..." cd /app exec uvicorn api.main:app \ --host 0.0.0.0 \ --port 8000 \ --log-level info \ --access-log \ --use-colors } # Funzione per avviare MCP server start_mcp_server() { echo "Starting MCP server on port 8001..." cd /app exec uvicorn mcp-server.server:mcp_app \ --host 0.0.0.0 \ --port 8001 \ --log-level info \ --access-log } # Funzione per avviare entrambi i server start_all_servers() { echo "Starting all servers..." # Start MCP server in background uvicorn mcp-server.server:mcp_app \ --host 0.0.0.0 \ --port 8001 \ --log-level info & MCP_PID=$! echo "MCP server started with PID $MCP_PID" # Start API server in foreground uvicorn api.main:app \ --host 0.0.0.0 \ --port 8000 \ --log-level info \ --access-log & API_PID=$! echo "API server started with PID $API_PID" # Wait for both processes wait $MCP_PID $API_PID } # Verifica che la documentazione sia stata compilata if [ ! -d "/app/site" ]; then echo "WARNING: Documentation site not found at /app/site" echo "Documentation will not be served until built." fi # Main execution case "$1" in server|api) start_api_server ;; mcp) start_mcp_server ;; all) start_all_servers ;; bash) exec /bin/bash ;; *) echo "Usage: $0 {server|mcp|all|bash}" echo " server - Start FastAPI documentation server (port 8000)" echo " mcp - Start MCP server (port 8001)" echo " all - Start both servers" echo " bash - Start bash shell" exit 1 ;; esac