mirror of
https://github.com/huge-dream/django-vue3-admin.git
synced 2026-09-25 13:51:02 +00:00
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.
77 lines
3.0 KiB
PowerShell
77 lines
3.0 KiB
PowerShell
# ============================================================
|
|
# Stop All 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-ServiceByName {
|
|
param([string]$Name, [string]$Pattern)
|
|
|
|
$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 service (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
|
|
}
|
|
Write-Host "[$Name] Stopped"
|
|
}
|
|
}
|
|
Remove-Item $pidFile -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
# Try to find by process name
|
|
$wmiQuery = "SELECT ProcessId, Name, CommandLine FROM Win32_Process WHERE Name LIKE '%$Pattern%' OR CommandLine LIKE '%$Pattern%'"
|
|
$procs = Get-WmiObject -Query $wmiQuery -ErrorAction SilentlyContinue
|
|
if ($procs) {
|
|
foreach ($p in $procs) {
|
|
Write-Host "[$Name] Found by pattern PID: $($p.ProcessId), stopping..."
|
|
Stop-Process -Id $p.ProcessId -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
}
|
|
|
|
# Stop each service
|
|
Stop-ServiceByName "backend" "uvicorn"
|
|
Stop-ServiceByName "frontend" "node"
|
|
Stop-ServiceByName "celery_worker" "celery"
|
|
Stop-ServiceByName "celery_beat" "celery"
|
|
|
|
# Additional cleanup
|
|
Write-Host "[Cleanup] Checking for residual processes..."
|
|
|
|
# Cleanup uvicorn
|
|
$wmiQuery = "SELECT ProcessId, Name FROM Win32_Process WHERE Name LIKE '%uvicorn%'"
|
|
Get-WmiObject -Query $wmiQuery -ErrorAction SilentlyContinue | ForEach-Object {
|
|
Write-Host "[Cleanup] Stopping uvicorn (PID: $($_.ProcessId))"
|
|
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
# Cleanup gunicorn
|
|
$wmiQuery = "SELECT ProcessId, Name FROM Win32_Process WHERE Name LIKE '%gunicorn%'"
|
|
Get-WmiObject -Query $wmiQuery -ErrorAction SilentlyContinue | ForEach-Object {
|
|
Write-Host "[Cleanup] Stopping gunicorn (PID: $($_.ProcessId))"
|
|
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
# Cleanup node/vite
|
|
$wmiQuery = "SELECT ProcessId, Name, CommandLine FROM Win32_Process WHERE Name LIKE '%node%' AND (CommandLine LIKE '%vite%' OR CommandLine LIKE '%dev%')"
|
|
Get-WmiObject -Query $wmiQuery -ErrorAction SilentlyContinue | ForEach-Object {
|
|
Write-Host "[Cleanup] Stopping vite (PID: $($_.ProcessId))"
|
|
Stop-Process -Id $_.ProcessId -Force -ErrorAction SilentlyContinue
|
|
}
|
|
|
|
Write-Host "[Done] All services stopped"
|
|
exit 0
|