- dev/dev.ps1: 一键启动后端(编译后运行)+前端(4321),校验 CORS 与 astro dev 单实例锁 - dev/stop.ps1: 按 PID 登记停止,-Force 清残留 - dev/status.ps1: 端口/PID/健康检查一览 - dev/doctor.ps1: 工具链/路径/依赖/数据库/端口/CORS 体检 - vision/vision.ps1: CLIP 向量服务起停 - lib/common.ps1: 路径探测、端口、进程登记、HTTP 探测 - config/local.env.example: 路径与端口覆盖模板
63 lines
2.7 KiB
PowerShell
63 lines
2.7 KiB
PowerShell
# dev/status.ps1 — 查看本地开发环境状态(端口 / PID / 健康检查)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$CliRoot = Split-Path -Parent $PSScriptRoot
|
|
. (Join-Path $CliRoot 'lib\common.ps1')
|
|
|
|
$envMap = Import-LocalEnv (Join-Path $CliRoot 'config\local.env')
|
|
$backendPort = [int](Get-Setting $envMap 'BACKEND_PORT' '8090')
|
|
$frontendPort = [int](Get-Setting $envMap 'FRONTEND_PORT' '4321')
|
|
$visionPort = [int](Get-Setting $envMap 'VISION_PORT' '8900')
|
|
|
|
# 注意:不要写成 @( cmd1, cmd2 ) —— PowerShell 会把逗号当成 cmd1 的参数分隔符
|
|
$stBackend = Get-ServiceStatus -Name 'backend' -Port $backendPort -HealthUrl "http://127.0.0.1:$backendPort/api/health"
|
|
$stFrontend = Get-ServiceStatus -Name 'frontend' -Port $frontendPort -HealthUrl "http://127.0.0.1:$frontendPort/cn/runway-looks/"
|
|
$stVision = Get-ServiceStatus -Name 'vision' -Port $visionPort -HealthUrl "http://127.0.0.1:$visionPort/health"
|
|
$rows = @($stBackend, $stFrontend, $stVision)
|
|
|
|
# 后端另外两个内部端口只做占用展示
|
|
$internal = @(
|
|
@{ Name = 'ssg'; Port = 8091 },
|
|
@{ Name = 'backstage'; Port = 8092 }
|
|
)
|
|
|
|
Write-Host ''
|
|
Write-Host ' 本地开发环境状态' -ForegroundColor White
|
|
Write-Host ' ----------------------------------------------' -ForegroundColor DarkGray
|
|
Write-Host (' {0,-10} {1,-6} {2,-8} {3,-10} {4}' -f '服务', '端口', 'PID', '监听', '健康') -ForegroundColor DarkGray
|
|
|
|
foreach ($r in $rows) {
|
|
$listen = '否'
|
|
if ($r.Listening) { $listen = '是' }
|
|
$health = '否'
|
|
if ($r.Healthy) { $health = '是' }
|
|
$color = 'Gray'
|
|
if ($r.Healthy) { $color = 'Green' }
|
|
elseif ($r.Listening) { $color = 'Yellow' }
|
|
$pidText = '-'
|
|
if ($r.Pid -gt 0) { $pidText = [string]$r.Pid }
|
|
elseif ($r.OwnerPid -gt 0) { $pidText = [string]$r.OwnerPid + '*' }
|
|
Write-Host (' {0,-10} {1,-6} {2,-8} {3,-10} {4}' -f $r.Name, $r.Port, $pidText, $listen, $health) -ForegroundColor $color
|
|
}
|
|
|
|
# 8091/8092 属于后端同一进程,占用者等于登记的 backend PID 时不算「野进程」
|
|
$backendPid = Get-ServicePid 'backend'
|
|
foreach ($i in $internal) {
|
|
$listen = '否'
|
|
$pidText = '-'
|
|
if (Test-PortInUse $i.Port) {
|
|
$listen = '是'
|
|
$owner = Get-PortOwnerPid $i.Port
|
|
if ($backendPid -gt 0 -and $owner -eq $backendPid) {
|
|
$pidText = [string]$owner
|
|
} else {
|
|
$pidText = [string]$owner + '*'
|
|
}
|
|
}
|
|
Write-Host (' {0,-10} {1,-6} {2,-8} {3,-10} {4}' -f $i.Name, $i.Port, $pidText, $listen, '-') -ForegroundColor DarkGray
|
|
}
|
|
|
|
Write-Host ''
|
|
Write-Note '* = 端口被占用,但不是 dev.ps1 登记的进程(可能是手动启动的)'
|
|
Write-Note '启动:.\dev\dev.ps1 停止:.\dev\stop.ps1 体检:.\dev\doctor.ps1'
|