oclaw/runtime/operations/scripts/stop_wiki_worker.ps1
oliver 38de5a305f fix(scripts): resolve repo root by searching oclaw.json
Make start/stop scripts robust to directory renames, and improve stop hints when process termination is denied.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-09 11:41:24 +08:00

47 lines
1.3 KiB
PowerShell

param(
[switch]$Force
)
$ErrorActionPreference = "Stop"
$runDir = Join-Path $PSScriptRoot ".run"
$pidFile = Join-Path $runDir "wiki_worker.pid"
function Warn([string]$msg) {
Write-Host "[WARN] $msg" -ForegroundColor Yellow
}
function Warn-AccessHint([string]$contextMsg) {
Warn $contextMsg
Write-Host " Hint: If you see 'Access is denied', re-run this terminal as Administrator." -ForegroundColor Yellow
}
if (-not (Test-Path $pidFile)) {
Write-Host "[ok] not running (no pid file)"
exit 0
}
$procId = (Get-Content -Path $pidFile -ErrorAction SilentlyContinue | Select-Object -First 1)
if (-not $procId) {
Remove-Item -Force $pidFile -ErrorAction SilentlyContinue
Write-Host "[ok] not running (empty pid file)"
exit 0
}
try {
if ($Force) {
taskkill.exe /PID $procId /T /F | Out-Null
} else {
taskkill.exe /PID $procId /T | Out-Null
}
} catch {
$msg = "$($_.Exception.Message)"
if ($msg -match "denied|Access is denied|0x80070005|拒绝访问|拒绝") {
Warn-AccessHint "Failed to stop wiki worker pid=$procId : $msg"
} else {
Warn "Failed to stop wiki worker pid=$procId : $msg"
Write-Host " Hint: If the process cannot be stopped due to permissions, re-run as Administrator." -ForegroundColor Yellow
}
}
Remove-Item -Force $pidFile -ErrorAction SilentlyContinue
Write-Host "[ok] stopped pid=$procId"