瀏覽代碼

fix startup

spacexerq 1 周之前
父節點
當前提交
45ccaaf5b1
共有 4 個文件被更改,包括 58 次插入32 次删除
  1. 2 1
      services/orchestrator/orchestrator/clients/spec_cl.py
  2. 19 4
      services/spectrometer/AddDevices.bat
  3. 20 17
      start.ps1
  4. 17 10
      update.ps1

+ 2 - 1
services/orchestrator/orchestrator/clients/spec_cl.py

@@ -9,7 +9,8 @@ class SpectrometerClient:
                  username: Optional[str] = None, password: Optional[str] = None,
                  timeout_s: float = 30.0):
         self.base = base_url.rstrip("/")
-        self.auth = HTTPBasicAuth(username, password) if username and password else None
+        # Auth removed: spectrometer API is open (local lab device)
+        self.auth = None
         self.timeout = timeout_s
 
         # DRF root autodiscovery

+ 19 - 4
services/spectrometer/AddDevices.bat

@@ -1,7 +1,22 @@
-curl -v -u specadmin:specadmin -X POST -H "Content-Type: application/json" -d "{\"device_type\": \"ADC\", \"brend\": \"Picoscope\", \"serial_model\": \"PS4000A\", \"proto\": \"adc_default\", \"proto_interface\": \"TCP\"}" http://localhost:8000/api/devices/
+@echo off
+REM Register hardware devices in the spectrometer database (run once after first start)
 
-curl -v -u specadmin:specadmin -X POST -H "Content-Type: application/json" -d "{\"device_type\": \"SDR\", \"brend\": \"HackRF\", \"serial_model\": \"HackRF\", \"proto\": \"sdr_default\", \"proto_interface\": \"USB\"}" http://localhost:8000/api/devices/
+curl -s -X POST -H "Content-Type: application/json" ^
+  -d "{\"device_type\": \"ADC\", \"brend\": \"Picoscope\", \"serial_model\": \"PS4000A\", \"proto\": \"adc_default\", \"proto_interface\": \"TCP\"}" ^
+  http://localhost:8000/api/devices/
 
-curl -v -u specadmin:specadmin -X POST -H "Content-Type: application/json" -d "{\"device_type\": \"SYNC\", \"brend\": \"Arduino\", \"serial_model\": \"DuePP\", \"proto\": \"sync_default\", \"proto_interface\": \"USB\"}" http://localhost:8000/api/devices/
+curl -s -X POST -H "Content-Type: application/json" ^
+  -d "{\"device_type\": \"SDR\", \"brend\": \"HackRF\", \"serial_model\": \"HackRF\", \"proto\": \"sdr_default\", \"proto_interface\": \"USB\"}" ^
+  http://localhost:8000/api/devices/
 
-curl -v -u specadmin:specadmin -X POST -H "Content-Type: application/json" -d "{\"device_type\": \"GRA\", \"brend\": \"ITMO\", \"serial_model\": \"GRU\", \"proto\": \"gra_default\", \"proto_interface\": \"UDP\"}" http://localhost:8000/api/devices/
+curl -s -X POST -H "Content-Type: application/json" ^
+  -d "{\"device_type\": \"SYNC\", \"brend\": \"Arduino\", \"serial_model\": \"DuePP\", \"proto\": \"sync_default\", \"proto_interface\": \"USB\"}" ^
+  http://localhost:8000/api/devices/
+
+curl -s -X POST -H "Content-Type: application/json" ^
+  -d "{\"device_type\": \"GRA\", \"brend\": \"ITMO\", \"serial_model\": \"GRU\", \"proto\": \"gra_default\", \"proto_interface\": \"UDP\"}" ^
+  http://localhost:8000/api/devices/
+
+echo.
+echo Devices registered.
+pause

+ 20 - 17
start.ps1

@@ -211,20 +211,31 @@ if (-not $GuiOnly) {
         @{ Name = "Seq-Interp";    Url = "http://localhost:$(Get-EnvPort 'SEQ_INTERP_PORT'    '7475')/health"; Required = $true      },
         @{ Name = "Reconstructor"; Url = "http://localhost:$(Get-EnvPort 'RECONSTRUCTOR_PORT' '8081')/health"; Required = $true      },
         @{ Name = "Spectroscopy";  Url = "http://localhost:$(Get-EnvPort 'SPECTROSCOPY_PORT'  '8002')/health"; Required = $true      },
-        @{ Name = "Spectrometer";  Url = "http://localhost:$(Get-EnvPort 'SPECTROMETER_PORT'  '8000')/api/";  Required = $checkSpec  }
+        @{ Name = "Spectrometer";  Url = "http://localhost:$(Get-EnvPort 'SPECTROMETER_PORT'  '8000')/api/";  Required = $checkSpec; AllowedCodes = @(200,301,302,401,403) }
     )
 
     $maxWait = 120; $interval = 3; $elapsed = 0
+    # Helper: returns $true if the TCP port is accepting connections.
+    # Using TCP instead of HTTP so HTTP 4xx / auth errors don't cause false negatives.
+    function Test-ServiceUp($svc) {
+        try {
+            $uri  = [System.Uri]$svc.Url
+            $port = if ($uri.Port -gt 0) { $uri.Port } else { 80 }
+            $tcp  = New-Object System.Net.Sockets.TcpClient
+            $ar   = $tcp.BeginConnect($uri.Host, $port, $null, $null)
+            $ok   = $ar.AsyncWaitHandle.WaitOne(1500, $false)
+            try { $tcp.Close() } catch {}
+            return $ok
+        } catch {
+            return $false
+        }
+    }
+
     while ($elapsed -lt $maxWait) {
         $pending = @()
         foreach ($svc in $services) {
             if (-not $svc.Required) { continue }
-            $up = $false
-            try {
-                $r  = Invoke-WebRequest $svc.Url -UseBasicParsing -TimeoutSec 2 -ErrorAction Stop
-                $up = ($r.StatusCode -lt 400)
-            } catch {}
-            if (-not $up) { $pending += $svc.Name }
+            if (-not (Test-ServiceUp $svc)) { $pending += $svc.Name }
         }
         if ($pending.Count -eq 0) { Write-OK "All required services healthy"; break }
         Write-Host ("    ... {0}/{1} s  waiting: {2}" -f $elapsed, $maxWait, ($pending -join ", ")) -ForegroundColor DarkGray
@@ -235,18 +246,10 @@ if (-not $GuiOnly) {
 
     Write-Host ""
     foreach ($svc in $services) {
-        $ok = $false
-        try {
-            $r  = Invoke-WebRequest $svc.Url -UseBasicParsing -TimeoutSec 2 -ErrorAction Stop
-            $ok = ($r.StatusCode -lt 400)
-        } catch {}
+        $ok = Test-ServiceUp $svc
         $icon  = if ($ok) { "[OK]" } else { "[--]" }
         $color = if ($ok) { "Green" } elseif ($svc.Required) { "Yellow" } else { "DarkGray" }
-        if (-not $svc.Required -and -not $ok) {
-            $suffix = "  (native -- start manually)"
-        } else {
-            $suffix = ""
-        }
+        $suffix = if (-not $svc.Required -and -not $ok) { "  (native -- start manually)" } else { "" }
         Write-Host ("    {0,-6} {1,-16} {2}{3}" -f $icon, $svc.Name, $svc.Url, $suffix) -ForegroundColor $color
     }
 

+ 17 - 10
update.ps1

@@ -133,14 +133,24 @@ $checks = @(
     @{ Name = "Spectrometer*"; Url = "http://localhost:$(Get-EnvPort 'SPECTROMETER_PORT'   '8000')/api/";  Native = $true  }
 )
 
+function Test-Port($url) {
+    try {
+        $uri  = [System.Uri]$url
+        $port = if ($uri.Port -gt 0) { $uri.Port } else { 80 }
+        $tcp  = New-Object System.Net.Sockets.TcpClient
+        $ar   = $tcp.BeginConnect($uri.Host, $port, $null, $null)
+        $ok   = $ar.AsyncWaitHandle.WaitOne(1500, $false)
+        try { $tcp.Close() } catch {}
+        return $ok
+    } catch { return $false }
+}
+
 $maxWait = 60; $interval = 3; $elapsed = 0
 while ($elapsed -lt $maxWait) {
     $pending = @()
     foreach ($c in $checks) {
-        try {
-            $r = Invoke-WebRequest $c.Url -UseBasicParsing -TimeoutSec 2 -ErrorAction Stop
-            if ($r.StatusCode -ge 400) { $pending += $c.Name }
-        } catch { $pending += $c.Name }
+        if ($c.Native) { continue }   # native services not waited on
+        if (-not (Test-Port $c.Url)) { $pending += $c.Name }
     }
     if ($pending.Count -eq 0) { break }
     Write-Host ("    ... {0}/{1} s  waiting: {2}" -f $elapsed, $maxWait, ($pending -join ", ")) -ForegroundColor DarkGray
@@ -149,12 +159,9 @@ while ($elapsed -lt $maxWait) {
 
 Write-Host ""
 foreach ($c in $checks) {
-    try {
-        $r  = Invoke-WebRequest $c.Url -UseBasicParsing -TimeoutSec 2 -ErrorAction Stop
-        $ok = $r.StatusCode -lt 400
-    } catch { $ok = $false }
-    $icon   = if ($ok) { "[OK]" } else { "[--]" }
-    $color  = if ($ok) { "Green" } elseif ($c.Native) { "DarkGray" } else { "Yellow" }
+    $ok    = Test-Port $c.Url
+    $icon  = if ($ok) { "[OK]" } else { "[--]" }
+    $color = if ($ok) { "Green" } elseif ($c.Native) { "DarkGray" } else { "Yellow" }
     $suffix = if ($c.Native) { "  (native -- start manually if needed)" } else { "" }
     Write-Host ("    {0,-6} {1,-16} {2}{3}" -f $icon, $c.Name, $c.Url, $suffix) -ForegroundColor $color
 }