Files
django-vue3-admin/scripts/check-status.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

104 lines
2.7 KiB
PowerShell

# ============================================================
# Check Service Status (Windows PowerShell)
# ============================================================
$ErrorActionPreference = "Continue"
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$ProjectRoot = Split-Path -Parent $ScriptDir
$PID_DIR = Join-Path $ProjectRoot ".pids"
function Test-ServicePort {
param([int]$Port)
try {
$tcpClient = New-Object System.Net.Sockets.TcpClient
$tcpClient.Connect("localhost", $Port)
$tcpClient.Close()
return $true
} catch {
return $false
}
}
function Check-Service {
param([string]$Name, [int]$Port = 0)
Write-Host -NoNewline " $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 "Running (PID: $pid)"
return 0
}
}
}
# Check process name - PowerShell 5.1 compatible using WMI
$patterns = @{
"backend" = @("uvicorn", "gunicorn", "python")
"frontend" = @("node", "npm")
"celery_worker" = @("celery")
"celery_beat" = @("celery")
}
if ($patterns.ContainsKey($Name)) {
foreach ($pattern in $patterns[$Name]) {
# Use WMI for reliable cross-version process matching
$wmiQuery = "SELECT ProcessId, Name, CommandLine FROM Win32_Process WHERE Name LIKE '%$pattern%'"
$procs = Get-WmiObject -Query $wmiQuery -ErrorAction SilentlyContinue | Select-Object -First 1
if ($procs) {
Write-Host "Running (PID: $($procs.ProcessId))"
return 0
}
}
}
# Check port
if ($Port -gt 0) {
if (Test-ServicePort -Port $Port) {
Write-Host "Running (Port: $Port)"
return 0
}
}
Write-Host "Not running"
return 1
}
Write-Host ""
Write-Host "========================================"
Write-Host " Service Status Check"
Write-Host "========================================"
Write-Host ""
Check-Service "backend" 8000
Check-Service "frontend" 8080
Check-Service "celery_worker"
Check-Service "celery_beat"
Write-Host ""
# Port check
Write-Host "Port Check:"
Write-Host -NoNewline " 8000 (backend): "
if (Test-ServicePort -Port 8000) {
Write-Host "Open"
} else {
Write-Host "Closed"
}
Write-Host -NoNewline " 8080 (frontend): "
if (Test-ServicePort -Port 8080) {
Write-Host "Open"
} else {
Write-Host "Closed"
}
Write-Host ""
exit 0