mirror of
https://github.com/huge-dream/django-vue3-admin.git
synced 2026-09-25 21:57:46 +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.
61 lines
1.7 KiB
Bash
61 lines
1.7 KiB
Bash
#!/bin/bash
|
|
# ============================================================
|
|
# Stop All Services
|
|
# 使用方法: ./stop-all.sh
|
|
# ============================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
PID_DIR="$PROJECT_ROOT/.pids"
|
|
|
|
stop_service() {
|
|
local name=$1
|
|
local pid_file="$PID_DIR/$name.pid"
|
|
|
|
if [ -f "$pid_file" ]; then
|
|
local pid=$(cat "$pid_file")
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
echo "[$name] 停止服务 (PID: $pid)..."
|
|
kill "$pid" 2>/dev/null || true
|
|
sleep 1
|
|
# 强制停止
|
|
if kill -0 "$pid" 2>/dev/null; then
|
|
kill -9 "$pid" 2>/dev/null || true
|
|
fi
|
|
echo "[$name] 已停止"
|
|
else
|
|
echo "[$name] 未运行"
|
|
fi
|
|
rm -f "$pid_file"
|
|
else
|
|
# 尝试通过进程名查找
|
|
local pids=$(pgrep -f "$name" 2>/dev/null || true)
|
|
if [ -n "$pids" ]; then
|
|
echo "[$name] 通过进程名找到 PID: $pids,停止..."
|
|
echo "$pids" | xargs kill 2>/dev/null || true
|
|
fi
|
|
fi
|
|
}
|
|
|
|
# 停止各个服务
|
|
stop_service "backend"
|
|
stop_service "frontend"
|
|
stop_service "celery_worker"
|
|
stop_service "celery_beat"
|
|
|
|
# 额外清理残留进程
|
|
echo "[清理] 检查残留进程..."
|
|
|
|
# 清理 uvicorn
|
|
pkill -f "uvicorn.*application.asgi" 2>/dev/null || true
|
|
pkill -f "gunicorn.*application.asgi" 2>/dev/null || true
|
|
|
|
# 清理 celery
|
|
pkill -f "celery.*worker" 2>/dev/null || true
|
|
pkill -f "celery.*beat" 2>/dev/null || true
|
|
|
|
# 清理 vite
|
|
pkill -f "vite" 2>/dev/null || true
|
|
|
|
echo "[完成] 所有服务已停止"
|