Files
crypto_key/pm2-start.ps1
T
2026-05-19 01:00:26 +08:00

30 lines
1.2 KiB
PowerShell

# 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 ""
$lan = (Get-NetIPAddress -AddressFamily IPv4 -ErrorAction SilentlyContinue | Where-Object { $_.IPAddress -notmatch '^127\.' -and $_.PrefixOrigin -ne 'WellKnown' } | Select-Object -First 1).IPAddress
Write-Host "已启动。本机: http://127.0.0.1:5200" -ForegroundColor Green
if ($lan) { Write-Host "局域网: http://${lan}:5200" -ForegroundColor Green }
Write-Host "查看状态: pm2 status" -ForegroundColor Cyan
Write-Host "查看日志: pm2 logs api-key-manager" -ForegroundColor Cyan