start.ps1 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # ==============================================================================
  2. # lf_mri_platform -- Start services and GUI
  3. # Usage:
  4. # .\start.ps1 -- start Docker services + GUI
  5. # .\start.ps1 -GuiOnly -- start GUI only (no Docker)
  6. # .\start.ps1 -Mode real -- start in real hardware mode
  7. # .\start.ps1 -ServicesOnly -- start Docker services only
  8. # ==============================================================================
  9. param(
  10. [switch]$GuiOnly,
  11. [switch]$ServicesOnly,
  12. [ValidateSet("plug", "real")]
  13. [string]$Mode = "plug"
  14. )
  15. $ErrorActionPreference = "Stop"
  16. $Root = $PSScriptRoot
  17. $GuiDir = Join-Path $Root "apps\gui"
  18. $venvPython = Join-Path $GuiDir ".venv\Scripts\python.exe"
  19. $appScript = Join-Path $GuiDir "app.py"
  20. function Write-Step($msg) { Write-Host "`n==> $msg" -ForegroundColor Cyan }
  21. function Write-OK($msg) { Write-Host " [OK] $msg" -ForegroundColor Green }
  22. function Write-Warn($msg) { Write-Host " [!!] $msg" -ForegroundColor Yellow }
  23. # -- Start Docker services ----------------------------------------------------
  24. if (-not $GuiOnly) {
  25. Write-Step "Starting Docker services (mode: $Mode)"
  26. try { & docker info *>$null }
  27. catch {
  28. Write-Warn "Docker is not running. Starting Docker Desktop..."
  29. Start-Process "C:\Program Files\Docker\Docker\Docker Desktop.exe" -ErrorAction SilentlyContinue
  30. Write-Host " Waiting 20 seconds for Docker to start..."
  31. Start-Sleep 20
  32. }
  33. $envFile = Join-Path $Root ".env"
  34. if (-not (Test-Path $envFile)) {
  35. Copy-Item (Join-Path $Root ".env.example") $envFile
  36. Write-Warn ".env not found -- created from .env.example"
  37. }
  38. $env:ORCHESTRATOR_MODE = $Mode
  39. & docker compose --env-file $envFile up --build -d
  40. Write-OK "Services started in '$Mode' mode"
  41. Write-Host " Waiting for services to become healthy..." -ForegroundColor DarkGray
  42. $maxWait = 60
  43. $elapsed = 0
  44. $orchPort = (Get-Content $envFile | Select-String "ORCHESTRATOR_PORT=(\d+)").Matches[0].Groups[1].Value
  45. if (-not $orchPort) { $orchPort = "1717" }
  46. while ($elapsed -lt $maxWait) {
  47. try {
  48. $r = Invoke-WebRequest "http://localhost:$orchPort/health" -UseBasicParsing -TimeoutSec 2 -ErrorAction SilentlyContinue
  49. if ($r.StatusCode -eq 200) { Write-OK "Orchestrator is up (http://localhost:$orchPort)"; break }
  50. } catch {}
  51. Start-Sleep 3
  52. $elapsed += 3
  53. Write-Host " ... $elapsed/$maxWait s" -ForegroundColor DarkGray
  54. }
  55. if ($elapsed -ge $maxWait) {
  56. Write-Warn "Orchestrator not responding after ${maxWait}s -- GUI will use local fallback"
  57. }
  58. }
  59. # -- Start GUI ----------------------------------------------------------------
  60. if (-not $ServicesOnly) {
  61. Write-Step "Starting LF-MRI GUI"
  62. if (-not (Test-Path $venvPython)) {
  63. Write-Warn "Venv not found. Run .\install.ps1 first. Falling back to system Python..."
  64. $venvPython = "python"
  65. }
  66. Write-OK "Launching GUI..."
  67. Start-Process $venvPython -ArgumentList "`"$appScript`"" `
  68. -WorkingDirectory $Root `
  69. -WindowStyle Normal
  70. }
  71. # -- Status summary -----------------------------------------------------------
  72. Write-Host ""
  73. Write-Host " Service endpoints:" -ForegroundColor White
  74. Write-Host " Orchestrator http://localhost:1717/docs"
  75. Write-Host " Seq-Interp http://localhost:7475/docs"
  76. Write-Host " Spectrometer http://localhost:8000/admin/"
  77. Write-Host " Reconstructor http://localhost:8081/docs"
  78. Write-Host " Spectroscopy http://localhost:8002/docs"
  79. Write-Host ""
  80. Write-Host " Stop services: .\stop.ps1"