# PM2 启动脚本 (Windows PowerShell) # 用法: .\pm2-start.ps1 $ErrorActionPreference = "Stop" $Root = Split-Path -Parent $MyInvocation.MyCommand.Path Set-Location $Root if (-not (Get-Command pm2 -ErrorAction SilentlyContinue)) { Write-Host "[错误] 未找到 pm2,请先执行: npm install -g pm2" -ForegroundColor Red exit 1 } $venvPy = Join-Path $Root "venv\Scripts\python.exe" if (-not (Test-Path $venvPy)) { Write-Host "[警告] 未检测到 venv,请先运行: python -m venv venv ; .\venv\Scripts\activate ; pip install -r requirements.txt" -ForegroundColor Yellow } if (-not (Test-Path "logs")) { New-Item -ItemType Directory -Path "logs" | Out-Null } pm2 start ecosystem.config.cjs pm2 save 2>$null Write-Host "" Write-Host "已启动。访问: http://127.0.0.1:5200" -ForegroundColor Green Write-Host "查看状态: pm2 status" -ForegroundColor Cyan Write-Host "查看日志: pm2 logs api-key-manager" -ForegroundColor Cyan