deerflow-code/scripts/stop-backend.ps1
2026-09-07 18:24:55 +08:00

21 lines
744 B
PowerShell

. "$PSScriptRoot\env.ps1"
$PidFile = Join-Path $PidDir "backend.pid"
if (-not (Test-Path -LiteralPath $PidFile)) {
Write-Host "Backend is not running (no pid file)."
exit 0
}
$rawPid = Get-Content -LiteralPath $PidFile | Select-Object -First 1
$processId = 0
if (-not [int]::TryParse([string]$rawPid, [ref]$processId) -or -not (Get-Process -Id $processId -ErrorAction SilentlyContinue)) {
Remove-Item -LiteralPath $PidFile -Force -ErrorAction SilentlyContinue
Write-Host "Backend is not running (stale pid file removed)."
exit 0
}
Write-Host "Stopping backend (pid $processId)..."
Stop-ProcessTree -ProcessId $processId
Remove-Item -LiteralPath $PidFile -Force -ErrorAction SilentlyContinue
Write-Host "Backend stopped."