57 lines
1.9 KiB
PowerShell
57 lines
1.9 KiB
PowerShell
# Restart backend API (uvicorn) and Celery worker only; does not stop frontend/Redis.$ErrorActionPreference = "Continue"
|
|
$RepoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$Backend = Join-Path $RepoRoot "backend"
|
|
$ApiPort = 8037
|
|
|
|
Write-Host "== Stop API + Celery only ==" -ForegroundColor Cyan
|
|
|
|
function Stop-ByCommandLine([string]$pattern, [string]$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
|
|
}
|
|
}
|
|
}
|
|
|
|
Stop-ByCommandLine "uvicorn\s+app\.main:app" "backend-api"
|
|
Stop-ByCommandLine "celery\s+-A\s+app\.core\.celery_app\s+worker" "celery-worker"
|
|
|
|
Start-Sleep -Seconds 2
|
|
|
|
Write-Host "== Start API on $ApiPort + Celery ==" -ForegroundColor Cyan
|
|
|
|
Start-Process powershell -ArgumentList @(
|
|
"-NoExit",
|
|
"-NoProfile",
|
|
"-ExecutionPolicy", "Bypass",
|
|
"-Command",
|
|
"Set-Location '$Backend'; .\venv\Scripts\Activate.ps1; python -m uvicorn app.main:app --host 0.0.0.0 --port $ApiPort"
|
|
)
|
|
|
|
Start-Process powershell -ArgumentList @(
|
|
"-NoExit",
|
|
"-NoProfile",
|
|
"-ExecutionPolicy", "Bypass",
|
|
"-Command",
|
|
"Set-Location '$Backend'; .\venv\Scripts\Activate.ps1; python -m celery -A app.core.celery_app worker --loglevel=info --pool=threads --concurrency=8"
|
|
)
|
|
|
|
Write-Host ""
|
|
Write-Host "[DONE] 已在新窗口启动 API 与 Celery (请查看弹出的 PowerShell 窗口日志)" -ForegroundColor Green
|
|
Write-Host "API: http://127.0.0.1:$ApiPort/docs" -ForegroundColor Cyan
|
|
|
|
Start-Sleep -Seconds 2
|
|
Write-Host ""
|
|
Write-Host "Port $ApiPort :" -ForegroundColor Cyan
|
|
netstat -ano | findstr ":$ApiPort"
|