Files
django-vue3-admin/scripts/stop-celery.ps1
T
lewis_yan f6313a93ce feat: add cross-platform service management scripts
Add comprehensive scripts for managing PIS project services:
- start-backend.ps1/.sh: Start Django backend with uvicorn/gunicorn
- start-frontend.ps1/.sh: Start Vue frontend dev server
- start-celery.ps1/.sh: Start Celery worker and beat
- stop-all.ps1/.sh: Stop all services gracefully
- stop-celery.ps1/.sh: Stop Celery services only
- view-logs.ps1/.sh: View and tail log files
- check-status.ps1/.sh: Check service status and ports

Cross-platform support:
- Windows PowerShell scripts with English output (UTF-8 safe)
- Unix/Linux/macOS Bash scripts with Chinese output
- WMI queries for PowerShell 5.1 compatibility
- Unified Makefile and make.ps1 orchestrators

Also add scripts-documentation.md with comprehensive usage guide.
2026-04-01 19:11:45 +08:00

46 lines
1.6 KiB
PowerShell

# ============================================================
# Stop Celery Services (Windows PowerShell)
# ============================================================
$ErrorActionPreference = "Continue"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$ProjectRoot = Split-Path -Parent $ScriptDir
$PID_DIR = Join-Path $ProjectRoot ".pids"
function Stop-CeleryService {
param([string]$Name)
$pidFile = Join-Path $PID_DIR "$Name.pid"
if (Test-Path $pidFile) {
$pid = Get-Content $pidFile -ErrorAction SilentlyContinue
if ($pid) {
$proc = Get-Process -Id $pid -ErrorAction SilentlyContinue
if ($proc) {
Write-Host "[$Name] Stopping (PID: $pid)..."
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
Start-Sleep -Milliseconds 500
$proc = Get-Process -Id $pid -ErrorAction SilentlyContinue
if ($proc) {
Stop-Process -Id $pid -Force -ErrorAction SilentlyContinue
}
}
}
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
}
# Cleanup residual
$wmiQuery = "SELECT ProcessId, Name FROM Win32_Process WHERE Name LIKE '%celery%'"
Get-WmiObject -Query $wmiQuery -ErrorAction SilentlyContinue | ForEach-Object {
Write-Host "[Cleanup] Stopping celery (PID: $($_.ProcessId))"
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
}
}
Stop-CeleryService "celery_worker"
Stop-CeleryService "celery_beat"
Write-Host "[Done] Celery stopped"
exit 0