<# .SYNOPSIS Start ROA2WEB Backend Service .DESCRIPTION Starts the ROA2WEB backend Windows service and validates it's running properly. .EXAMPLE .\Start-ROA2WEB.ps1 #> [CmdletBinding()] param( [string]$ServiceName = "ROA2WEB-Backend", [int]$Timeout = 30 ) $ErrorActionPreference = "Stop" Write-Host "`n[*] Starting ROA2WEB Backend Service..." -ForegroundColor Cyan try { $service = Get-Service -Name $ServiceName -ErrorAction Stop if ($service.Status -eq "Running") { Write-Host " [OK] Service is already running" -ForegroundColor Green exit 0 } # Start service Start-Service -Name $ServiceName Write-Host " [*] Service start command issued" -ForegroundColor Yellow # Wait for service to start $elapsed = 0 while ($service.Status -ne "Running" -and $elapsed -lt $Timeout) { Start-Sleep -Seconds 1 $service.Refresh() $elapsed++ Write-Host " [*] Waiting for service to start... ($elapsed/$Timeout)" -ForegroundColor Yellow } if ($service.Status -eq "Running") { Write-Host " [OK] Service started successfully" -ForegroundColor Green # Wait a bit and test health endpoint Start-Sleep -Seconds 3 try { $response = Invoke-WebRequest -Uri "http://localhost:8000/health" -UseBasicParsing -TimeoutSec 5 if ($response.StatusCode -eq 200) { Write-Host " [OK] Health check passed" -ForegroundColor Green } } catch { Write-Host " [WARN] Health check failed (service may still be starting)" -ForegroundColor Yellow } exit 0 } else { Write-Host " [ERROR] Service failed to start (Status: $($service.Status))" -ForegroundColor Red Write-Host " Check logs: C:\inetpub\wwwroot\roa2web\logs\backend-stderr.log" -ForegroundColor Yellow exit 1 } } catch { Write-Host " [ERROR] Failed to start service: $_" -ForegroundColor Red exit 1 }