mirror of
https://github.com/huge-dream/django-vue3-admin.git
synced 2026-09-22 13:05:16 +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.
73 lines
1.8 KiB
Bash
73 lines
1.8 KiB
Bash
#!/bin/bash
|
|
# ============================================================
|
|
# Start Frontend Service
|
|
# 使用方法: ./start-frontend.sh [dev|prod]
|
|
# ============================================================
|
|
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
|
|
FRONTEND_DIR="$PROJECT_ROOT/web"
|
|
PID_DIR="$PROJECT_ROOT/.pids"
|
|
LOG_DIR="$PROJECT_ROOT/backend/logs"
|
|
|
|
ENV=${1:-dev}
|
|
|
|
# 创建必要的目录
|
|
mkdir -p "$PID_DIR"
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
PID_FILE="$PID_DIR/frontend.pid"
|
|
LOG_FILE="$LOG_DIR/frontend.log"
|
|
|
|
# 检查是否已运行
|
|
if [ -f "$PID_FILE" ]; then
|
|
PID=$(cat "$PID_FILE")
|
|
if kill -0 "$PID" 2>/dev/null; then
|
|
echo "[前端] 已运行 (PID: $PID),跳过启动"
|
|
exit 0
|
|
else
|
|
echo "[前端] 清理旧的 PID 文件"
|
|
rm -f "$PID_FILE"
|
|
fi
|
|
fi
|
|
|
|
cd "$FRONTEND_DIR"
|
|
|
|
# 检查依赖
|
|
if [ ! -d "node_modules" ]; then
|
|
echo "[前端] 依赖未安装,正在安装..."
|
|
yarn install
|
|
fi
|
|
|
|
echo "[前端] 启动服务 (ENV=$ENV)..."
|
|
|
|
# 根据环境选择启动方式
|
|
if [ "$ENV" = "prod" ]; then
|
|
echo "[前端] 构建生产版本..."
|
|
yarn build
|
|
# 生产环境可以用 nginx 或静态服务器 served
|
|
echo "[前端] 生产构建完成,请使用静态服务器 serving"
|
|
else
|
|
# 开发环境
|
|
nohup yarn dev >> "$LOG_FILE" 2>&1 &
|
|
echo $! > "$PID_FILE"
|
|
fi
|
|
|
|
# 等待启动
|
|
sleep 5
|
|
|
|
# 检查是否成功启动
|
|
if [ -f "$PID_FILE" ]; then
|
|
PID=$(cat "$PID_FILE")
|
|
if kill -0 "$PID" 2>/dev/null; then
|
|
echo "[前端] 启动成功 (PID: $PID)"
|
|
echo "[前端] 访问地址: http://localhost:8080"
|
|
echo "[前端] 日志文件: $LOG_FILE"
|
|
else
|
|
echo "[前端] 启动失败,请检查日志: $LOG_FILE"
|
|
rm -f "$PID_FILE"
|
|
fi
|
|
fi
|