status-local.ps1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. $ErrorActionPreference = "Stop"
  2. Set-StrictMode -Version Latest
  3. $RepoRoot = (Resolve-Path (Join-Path $PSScriptRoot "..")).Path
  4. $RuntimeDir = Join-Path $RepoRoot ".runtime"
  5. $Services = @(
  6. @{
  7. Name = "web"
  8. Port = 3000
  9. Url = "http://localhost:3000"
  10. },
  11. @{
  12. Name = "api"
  13. Port = 3001
  14. Url = "http://localhost:3001/health"
  15. },
  16. @{
  17. Name = "extra"
  18. Port = 3002
  19. Url = "http://localhost:3002/health"
  20. }
  21. )
  22. function Get-PidFilePath([string]$Name) {
  23. return Join-Path $RuntimeDir "$Name.pid"
  24. }
  25. function Get-ListenerOwners([int]$Port) {
  26. try {
  27. return @(Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction Stop |
  28. Select-Object -ExpandProperty OwningProcess -Unique)
  29. } catch {
  30. return @()
  31. }
  32. }
  33. function Test-Url([string]$Url) {
  34. try {
  35. $response = Invoke-WebRequest -Uri $Url -UseBasicParsing -TimeoutSec 3
  36. return $response.StatusCode
  37. } catch {
  38. return $null
  39. }
  40. }
  41. Write-Host "SentAI local status" -ForegroundColor Cyan
  42. Write-Host "Repo: $RepoRoot"
  43. Write-Host ""
  44. foreach ($service in $Services) {
  45. [array]$owners = @(Get-ListenerOwners $service.Port)
  46. $statusCode = Test-Url $service.Url
  47. $pidFile = Get-PidFilePath $service.Name
  48. $pidText = if (Test-Path $pidFile) { (Get-Content $pidFile | Select-Object -First 1) } else { "-" }
  49. $ownerText = if ($owners.Count -gt 0) { $owners -join ", " } else { "-" }
  50. $httpText = if ($statusCode) { $statusCode } else { "-" }
  51. Write-Host "$($service.Name.PadRight(6)) port=$($service.Port) pid-file=$pidText owners=$ownerText http=$httpText"
  52. }