23 lines
807 B
PowerShell
23 lines
807 B
PowerShell
$ErrorActionPreference = 'Stop'
|
|
$apiPort = if ($env:API_PORT) { $env:API_PORT } else { '8100' }
|
|
|
|
$processIds = @()
|
|
$targets = Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -like "*app.main:app*--port $apiPort*" }
|
|
$processIds += $targets.ProcessId
|
|
$listeners = Get-NetTCPConnection -LocalPort ([int]$apiPort) -State Listen -ErrorAction SilentlyContinue
|
|
if ($listeners) {
|
|
$processIds += $listeners.OwningProcess
|
|
}
|
|
$processIds = $processIds | Where-Object { $_ } | Select-Object -Unique
|
|
|
|
if (-not $processIds) {
|
|
Write-Output 'domain-api 当前没有运行中的进程'
|
|
exit 0
|
|
}
|
|
|
|
foreach ($processId in $processIds) {
|
|
Stop-Process -Id $processId -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
Write-Output ("domain-api 已停止,进程数: " + (($processIds | Measure-Object).Count))
|