$ErrorActionPreference = "SilentlyContinue" Write-Host "== AIAgent stop ==" -ForegroundColor Cyan function Stop-ByCommandLine($pattern, $name) { $targets = Get-CimInstance Win32_Process | Where-Object { $_.CommandLine -and $_.CommandLine -match $pattern } if (-not $targets) { Write-Host "[SKIP] ${name}: no matching process" -ForegroundColor DarkGray return } foreach ($p in $targets) { try { Stop-Process -Id $p.ProcessId -Force Write-Host "[OK] stopped ${name} PID=$($p.ProcessId)" -ForegroundColor Green } catch { Write-Host "[WARN] failed to stop ${name} PID=$($p.ProcessId)" -ForegroundColor Yellow } } } # 1) 停后端 API(uvicorn app.main:app) Stop-ByCommandLine "uvicorn\s+app\.main:app" "backend-api" # 2) 停 Celery Worker Stop-ByCommandLine "celery\s+-A\s+app\.core\.celery_app\s+worker" "celery-worker" # 3) 停前端 dev(vite / pnpm dev / npm run dev) Stop-ByCommandLine "vite(\.js)?\s|pnpm\s+dev|npm\s+run\s+dev" "frontend-dev" # 4) 停 Redis(优先匹配本项目 redis-server) Stop-ByCommandLine "redis-server(\.exe)?(\s|$)" "redis" Start-Sleep -Milliseconds 600 Write-Host "" Write-Host "Port check:" -ForegroundColor Cyan foreach ($port in 3001, 8037, 8041, 6379) { $line = netstat -ano | Select-String ":$port\s+.*LISTENING" | Select-Object -First 1 if ($line) { Write-Host " - ${port}: LISTEN" -ForegroundColor Yellow } else { Write-Host " - ${port}: free" -ForegroundColor Green } } Write-Host "" Write-Host "DONE: stop script finished" -ForegroundColor Green