Files
wagtailcms/deploy/windows/install-nssm-services.ps1
T
Zhengen 1686794ad7 部署配置:新增 Windows Server 裸机部署流程
- requirements/production-windows.txt:Windows 专用生产依赖,用 waitress 替代
  不支持 Windows 的 gunicorn
- deploy/windows/serve-backend.ps1:waitress WSGI 启动脚本
- deploy/windows/install-nssm-services.ps1:用 NSSM 将前后端注册为 Windows 服务
- deploy/windows/nginx-wagtailcms.conf:nginx for Windows 反向代理模板(TCP 端口,
  不用 unix socket)
- documents/Windows服务器部署指南.md:完整部署步骤文档,并说明与 Linux 裸机
  部署(systemd/gunicorn/unix socket/Redis)的差异点
2026-09-11 09:39:30 +08:00

65 lines
2.5 KiB
PowerShell
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<#
使用 NSSM(Non-Sucking Service Manager,https://nssm.cc/download)将后端/前端
注册为 Windows 服务,实现开机自启 + 崩溃自动重启。
前置条件:
- 已下载 nssm.exe 并加入 PATH(或把完整路径填到 $Nssm 变量)
- 后端虚拟环境已就绪:<repo>\.venv
- 前端依赖已安装 + 已 `npm run build`:<repo>\frontend
用法(管理员 PowerShell):
cd C:\wagtailcms
.\deploy\windows\install-nssm-services.ps1
#>
$ErrorActionPreference = "Stop"
$Nssm = "nssm.exe" # 若 nssm 不在 PATH,改成绝对路径,如 "C:\tools\nssm-2.24\win64\nssm.exe"
$RepoRoot = Resolve-Path (Join-Path $PSScriptRoot "..\..")
$Powershell = (Get-Command powershell.exe).Source
function Install-NssmService {
param(
[string]$Name,
[string]$Application,
[string]$Arguments,
[string]$WorkingDirectory
)
& $Nssm stop $Name 2>$null | Out-Null
& $Nssm remove $Name confirm 2>$null | Out-Null
& $Nssm install $Name $Application $Arguments
& $Nssm set $Name AppDirectory $WorkingDirectory
& $Nssm set $Name AppStdout (Join-Path $WorkingDirectory "logs\$Name-stdout.log")
& $Nssm set $Name AppStderr (Join-Path $WorkingDirectory "logs\$Name-stderr.log")
& $Nssm set $Name AppRotateFiles 1
& $Nssm set $Name AppRotateBytes 10485760
& $Nssm set $Name Start SERVICE_AUTO_START
& $Nssm set $Name AppRestartDelay 5000
Write-Host "已注册服务:$Name" -ForegroundColor Green
}
New-Item -ItemType Directory -Force -Path (Join-Path $RepoRoot "logs") | Out-Null
New-Item -ItemType Directory -Force -Path (Join-Path $RepoRoot "frontend\logs") | Out-Null
# --- 后端:wagtailcms-backend(waitress WSGI,监听 127.0.0.1:8000) -------------
Install-NssmService `
-Name "wagtailcms-backend" `
-Application $Powershell `
-Arguments "-NoProfile -ExecutionPolicy Bypass -File `"$RepoRoot\deploy\windows\serve-backend.ps1`"" `
-WorkingDirectory $RepoRoot
# --- 前端:wagtailcms-frontend(Next.js, npm run start,监听 3000) -------------
$npmCmd = (Get-Command npm.cmd).Source
Install-NssmService `
-Name "wagtailcms-frontend" `
-Application $npmCmd `
-Arguments "run start" `
-WorkingDirectory (Join-Path $RepoRoot "frontend")
Write-Host ""
Write-Host "启动服务:Start-Service wagtailcms-backend; Start-Service wagtailcms-frontend" -ForegroundColor Yellow
Write-Host "查看状态:Get-Service wagtailcms-*" -ForegroundColor Yellow