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.
99 lines
3.0 KiB
PowerShell
99 lines
3.0 KiB
PowerShell
# ============================================================
|
|
# Start Frontend Service (Windows PowerShell)
|
|
# Usage: .\start-frontend.ps1 [dev|prod]
|
|
# ============================================================
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
|
|
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
|
|
$ProjectRoot = Split-Path -Parent $ScriptDir
|
|
$FrontendDir = Join-Path $ProjectRoot "web"
|
|
$PID_DIR = Join-Path $ProjectRoot ".pids"
|
|
$LOG_DIR = Join-Path $ProjectRoot "backend"
|
|
$LOG_DIR = Join-Path $LOG_DIR "logs"
|
|
|
|
$ENV = if ($args[0]) { $args[0] } else { "dev" }
|
|
|
|
# Create directories
|
|
if (!(Test-Path $PID_DIR)) { New-Item -ItemType Directory -Path $PID_DIR -Force | Out-Null }
|
|
if (!(Test-Path $LOG_DIR)) { New-Item -ItemType Directory -Path $LOG_DIR -Force | Out-Null }
|
|
|
|
$PID_FILE = Join-Path $PID_DIR "frontend.pid"
|
|
$LOG_FILE = Join-Path $LOG_DIR "frontend.log"
|
|
|
|
# Check if already running
|
|
if (Test-Path $PID_FILE) {
|
|
$PID = Get-Content $PID_FILE -ErrorAction SilentlyContinue
|
|
if ($PID -and (Get-Process -Id $PID -ErrorAction SilentlyContinue)) {
|
|
Write-Host "[Frontend] Already running (PID: $PID), skipping"
|
|
exit 0
|
|
} else {
|
|
Write-Host "[Frontend] Cleaning stale PID file"
|
|
Remove-Item $PID_FILE -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
Set-Location $FrontendDir
|
|
|
|
# Check if yarn is available
|
|
$yarnCmd = Get-Command yarn -ErrorAction SilentlyContinue
|
|
if (!$yarnCmd) {
|
|
Write-Host "[Frontend] yarn not found, trying npm..."
|
|
$npmCmd = Get-Command npm -ErrorAction SilentlyContinue
|
|
if (!$npmCmd) {
|
|
Write-Host "[Error] npm not installed"
|
|
exit 1
|
|
}
|
|
$useNpm = $true
|
|
} else {
|
|
$useNpm = $false
|
|
}
|
|
|
|
# Check dependencies
|
|
if (!(Test-Path "node_modules")) {
|
|
Write-Host "[Frontend] Dependencies not installed, installing..."
|
|
if ($useNpm) {
|
|
npm install
|
|
} else {
|
|
yarn install
|
|
}
|
|
}
|
|
|
|
Write-Host "[Frontend] Starting service (ENV=$ENV)..."
|
|
|
|
# Select startup method based on environment
|
|
if ($ENV -eq "prod") {
|
|
Write-Host "[Frontend] Building production version..."
|
|
if ($useNpm) {
|
|
npm run build
|
|
} else {
|
|
yarn build
|
|
}
|
|
Write-Host "[Frontend] Production build complete, use static server"
|
|
} else {
|
|
if ($useNpm) {
|
|
$proc = Start-Process -FilePath "npm" -ArgumentList "run dev" -WorkingDirectory $FrontendDir -PassThru -NoNewWindow
|
|
} else {
|
|
$proc = Start-Process -FilePath "yarn" -ArgumentList "dev" -WorkingDirectory $FrontendDir -PassThru -NoNewWindow
|
|
}
|
|
$proc.Id | Set-Content $PID_FILE
|
|
}
|
|
|
|
# Wait for startup
|
|
Start-Sleep -Seconds 5
|
|
|
|
# Check if started successfully
|
|
if (Test-Path $PID_FILE) {
|
|
$PID = Get-Content $PID_FILE
|
|
if (Get-Process -Id $PID -ErrorAction SilentlyContinue) {
|
|
Write-Host "[Frontend] Started successfully (PID: $PID)"
|
|
Write-Host "[Frontend] Access: http://localhost:8080"
|
|
Write-Host "[Frontend] Log file: $LOG_FILE"
|
|
} else {
|
|
Write-Host "[Frontend] Failed to start, check log: $LOG_FILE"
|
|
Remove-Item $PID_FILE -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
|
|
exit 0
|