51 lines
2.2 KiB
PowerShell
51 lines
2.2 KiB
PowerShell
# Legacy Windows compatibility only.
|
|
# NSSM supervises the single Python scheduler process; this script never creates
|
|
# Windows Task Scheduler entries and does not own business schedule rules.
|
|
param(
|
|
[string]$ProjectRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path,
|
|
[string]$DataRoot = "",
|
|
[string]$ServiceName = "gyxx-flow-scheduler",
|
|
[string]$NssmPath = "nssm.exe"
|
|
)
|
|
|
|
$ErrorActionPreference = "Stop"
|
|
Set-StrictMode -Version Latest
|
|
|
|
$project = (Resolve-Path -LiteralPath $ProjectRoot).Path
|
|
if ([string]::IsNullOrWhiteSpace($DataRoot)) {
|
|
$DataRoot = Join-Path $project "var"
|
|
}
|
|
$data = [IO.Path]::GetFullPath($DataRoot)
|
|
$python = Join-Path $project ".venv\Scripts\python.exe"
|
|
if (-not (Test-Path -LiteralPath $python -PathType Leaf)) {
|
|
throw "Python environment not found: $python"
|
|
}
|
|
$nssm = (Get-Command $NssmPath -ErrorAction Stop).Source
|
|
$serviceLogRoot = Join-Path $data "logs\scheduler-service"
|
|
New-Item -ItemType Directory -Path $serviceLogRoot -Force | Out-Null
|
|
|
|
function Invoke-Nssm([string[]]$Arguments) {
|
|
& $nssm @Arguments
|
|
if ($LASTEXITCODE -ne 0) {
|
|
throw "NSSM failed with exit code $LASTEXITCODE"
|
|
}
|
|
}
|
|
|
|
Invoke-Nssm -Arguments @("install", $ServiceName, $python)
|
|
Invoke-Nssm -Arguments @("set", $ServiceName, "AppDirectory", $project)
|
|
Invoke-Nssm -Arguments @("set", $ServiceName, "AppParameters", "-m gyxx_flow schedule run")
|
|
Invoke-Nssm -Arguments @(
|
|
"set", $ServiceName, "AppEnvironmentExtra",
|
|
"GYXX_PROJECT_ROOT=$project", "GYXX_DATA_ROOT=$data", "PYTHONUTF8=1"
|
|
)
|
|
Invoke-Nssm -Arguments @("set", $ServiceName, "AppStdout", (Join-Path $serviceLogRoot "service.log"))
|
|
Invoke-Nssm -Arguments @("set", $ServiceName, "AppStderr", (Join-Path $serviceLogRoot "service-error.log"))
|
|
Invoke-Nssm -Arguments @("set", $ServiceName, "AppRotateFiles", "1")
|
|
Invoke-Nssm -Arguments @("set", $ServiceName, "AppRotateBytes", "10485760")
|
|
Invoke-Nssm -Arguments @("set", $ServiceName, "AppExit", "Default", "Restart")
|
|
Invoke-Nssm -Arguments @("set", $ServiceName, "Start", "SERVICE_AUTO_START")
|
|
|
|
Write-Host "Service installed: $ServiceName"
|
|
Write-Host "Before starting it, set the Log On account and production environment as documented."
|
|
Write-Host "Start with: nssm start $ServiceName"
|