Files
gyxx-flow/deploy/windows-service/install.ps1
T
wangyunlong 130f06b320 feat(cookie-gate): 调度器恢复重跑接线与控制台健康自检
调度器维护循环挂载 CookieGateRecoveryManager,登录态恢复后按原业务日期自动
重跑被阻断工作流并飞书确认;工作流级 required_accounts 声明接入目录解析;
采集器抛 CookieExpiredError 退出 75;控制台新增 /api/health 自检端点与进程内
看门狗,配合 deploy/watchdog 双层保活;安装脚本同步。
2026-10-09 13:45:29 +08:00

62 lines
2.9 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]$RuntimeEnvFile = "D:\product-collector-analyze-flow\.env",
[string]$JushuitanEnvFile = "D:\product-collector-analyze-flow\private-secrets\jushuitan.env",
[string]$ServiceName = "gyxx-flow-scheduler",
[string]$NssmPath = "nssm.exe"
)
$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest
$project = (Resolve-Path -LiteralPath $ProjectRoot).Path
$runtimeEnvPath = (Resolve-Path -LiteralPath $RuntimeEnvFile -ErrorAction Stop).Path
$runtimeEnvPaths = @($runtimeEnvPath)
if (Test-Path -LiteralPath $JushuitanEnvFile -PathType Leaf) {
$runtimeEnvPaths += (Resolve-Path -LiteralPath $JushuitanEnvFile -ErrorAction Stop).Path
} else {
Write-Warning "Jushuitan environment file not found; Jushuitan workflows will fail safely until it is provisioned."
}
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)
$envFileArguments = $runtimeEnvPaths | ForEach-Object { '--env-file "' + $_ + '"' }
$schedulerArguments = '-m gyxx_flow schedule run ' + ($envFileArguments -join ' ')
Invoke-Nssm -Arguments @("set", $ServiceName, "AppParameters", $schedulerArguments)
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"