# Start Geutebruck API Services # This script starts GeViServer, SDK Bridge, and Python API $ErrorActionPreference = "Stop" Write-Host "========================================" -ForegroundColor Cyan Write-Host "Starting Geutebruck API Services" -ForegroundColor Cyan Write-Host "========================================" -ForegroundColor Cyan Write-Host "" # Paths $geviServerExe = "C:\GEVISOFT\GeViServer.exe" $sdkBridgePath = "C:\DEV\COPILOT\geutebruck-api\src\sdk-bridge\GeViScopeBridge\bin\Release\net8.0" $sdkBridgeExe = "$sdkBridgePath\GeViScopeBridge.exe" $apiPath = "C:\DEV\COPILOT\geutebruck-api\src\api" $venvPython = "C:\DEV\COPILOT\geutebruck-api\.venv\Scripts\python.exe" $uvicorn = "C:\DEV\COPILOT\geutebruck-api\.venv\Scripts\uvicorn.exe" # Function to wait for port to be listening function Wait-ForPort { param( [int]$Port, [int]$TimeoutSeconds = 60 ) $elapsed = 0 while ($elapsed -lt $TimeoutSeconds) { $connection = Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction SilentlyContinue if ($connection) { return $true } Start-Sleep -Seconds 2 $elapsed += 2 Write-Host "." -NoNewline -ForegroundColor Gray } return $false } # Check if already running $geviServerRunning = Get-Process -Name "GeViServer" -ErrorAction SilentlyContinue $sdkBridgeRunning = Get-Process -Name "GeViScopeBridge" -ErrorAction SilentlyContinue $uvicornRunning = Get-Process -Name "uvicorn" -ErrorAction SilentlyContinue # Start GeViServer if ($geviServerRunning) { Write-Host "[SKIP] GeViServer is already running (PID: $($geviServerRunning.Id))" -ForegroundColor Yellow } else { Write-Host "[1/3] Starting GeViServer..." -ForegroundColor Green Start-Process -FilePath $geviServerExe -ArgumentList "console" -WorkingDirectory "C:\GEVISOFT" -WindowStyle Hidden # Wait for GeViServer to start listening on port 7700 Write-Host " Waiting for GeViServer to initialize" -NoNewline -ForegroundColor Gray if (Wait-ForPort -Port 7700 -TimeoutSeconds 60) { Write-Host "" $process = Get-Process -Name "GeViServer" -ErrorAction SilentlyContinue Write-Host " [OK] GeViServer started (PID: $($process.Id))" -ForegroundColor Green } else { Write-Host "" Write-Host " [ERROR] GeViServer failed to start listening on port 7700" -ForegroundColor Red exit 1 } } # Start SDK Bridge if ($sdkBridgeRunning) { Write-Host "[SKIP] SDK Bridge is already running (PID: $($sdkBridgeRunning.Id))" -ForegroundColor Yellow } else { Write-Host "[2/3] Starting SDK Bridge..." -ForegroundColor Green Start-Process -FilePath $sdkBridgeExe -WorkingDirectory $sdkBridgePath -WindowStyle Hidden # Wait for SDK Bridge to start listening on port 50051 Write-Host " Waiting for SDK Bridge to connect" -NoNewline -ForegroundColor Gray if (Wait-ForPort -Port 50051 -TimeoutSeconds 30) { Write-Host "" $process = Get-Process -Name "GeViScopeBridge" -ErrorAction SilentlyContinue Write-Host " [OK] SDK Bridge started (PID: $($process.Id))" -ForegroundColor Green } else { Write-Host "" Write-Host " [ERROR] SDK Bridge failed to start listening on port 50051" -ForegroundColor Red exit 1 } } # Start Python API if ($uvicornRunning) { Write-Host "[SKIP] Python API is already running (PID: $($uvicornRunning.Id))" -ForegroundColor Yellow } else { Write-Host "[3/3] Starting Python API..." -ForegroundColor Green Start-Process -FilePath $uvicorn ` -ArgumentList "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload" ` -WorkingDirectory $apiPath ` -WindowStyle Hidden # Wait for API to start listening on port 8000 Write-Host " Waiting for API to initialize" -NoNewline -ForegroundColor Gray if (Wait-ForPort -Port 8000 -TimeoutSeconds 20) { Write-Host "" $process = Get-Process -Name "uvicorn" -ErrorAction SilentlyContinue Write-Host " [OK] Python API started (PID: $($process.Id))" -ForegroundColor Green } else { Write-Host "" Write-Host " [ERROR] Python API failed to start listening on port 8000" -ForegroundColor Red exit 1 } } Write-Host "" Write-Host "========================================" -ForegroundColor Green Write-Host "Services Started Successfully!" -ForegroundColor Green Write-Host "========================================" -ForegroundColor Green Write-Host "" Write-Host "GeViServer: Running on ports 7700-7703" -ForegroundColor Cyan Write-Host "SDK Bridge: Running on port 50051 (gRPC)" -ForegroundColor Cyan Write-Host "Python API: http://localhost:8000" -ForegroundColor Cyan Write-Host "Swagger UI: http://localhost:8000/docs" -ForegroundColor Cyan Write-Host "" Write-Host "To check status, run: .\status-services.ps1" -ForegroundColor Yellow Write-Host "To stop services, run: .\stop-services.ps1" -ForegroundColor Yellow