fix: Fixed agent windows version
This commit is contained in:
+39
-8
@@ -66,8 +66,17 @@ try {
|
||||
|
||||
$cfgDir = Join-Path $env:ProgramData "vantage"
|
||||
New-Item -ItemType Directory -Force -Path $cfgDir | Out-Null
|
||||
$cfgPath = Join-Path $cfgDir "config.yaml"
|
||||
|
||||
$cfg = @"
|
||||
# Preserve existing config on upgrade. A MajorUpgrade re-runs this script with
|
||||
# no SERVERID/TOKEN, so blindly rewriting would wipe the agent_token the agent
|
||||
# persisted after Register(). Only (re)write when a ServerId is supplied
|
||||
# (fresh install / explicit re-register).
|
||||
if ((Test-Path $cfgPath) -and (-not $ServerId)) {
|
||||
Write-Log "config.yaml exists and no ServerId supplied - preserving existing config (upgrade)"
|
||||
}
|
||||
else {
|
||||
$cfg = @"
|
||||
server_url: "$ServerUrl"
|
||||
server_id: "$ServerId"
|
||||
pre_reg_token: "$Token"
|
||||
@@ -75,12 +84,12 @@ agent_token: ""
|
||||
poll_interval: 30s
|
||||
tls: true
|
||||
"@
|
||||
$cfgPath = Join-Path $cfgDir "config.yaml"
|
||||
Set-Content -Path $cfgPath -Value $cfg -Encoding utf8
|
||||
Write-Log "wrote $cfgPath"
|
||||
Set-Content -Path $cfgPath -Value $cfg -Encoding utf8
|
||||
Write-Log "wrote $cfgPath"
|
||||
|
||||
# Lock down ACL: SYSTEM + Administrators only
|
||||
Invoke-Native -File "icacls" -Arguments @($cfgPath, "/inheritance:r", "/grant:r", "SYSTEM:F", "Administrators:F")
|
||||
# Lock down ACL: SYSTEM + Administrators only
|
||||
Invoke-Native -File "icacls" -Arguments @($cfgPath, "/inheritance:r", "/grant:r", "SYSTEM:F", "Administrators:F")
|
||||
}
|
||||
|
||||
if (-not $InstallDir) { $InstallDir = $PSScriptRoot }
|
||||
$nssm = Join-Path $InstallDir "nssm.exe"
|
||||
@@ -89,9 +98,31 @@ tls: true
|
||||
if (-not (Test-Path $nssm)) { throw "nssm.exe not found at $nssm" }
|
||||
if (-not (Test-Path $exe)) { throw "vantage-agent.exe not found at $exe" }
|
||||
|
||||
Invoke-Native -File $nssm -Arguments @("install", "VantageAgent", $exe)
|
||||
# Install only if the service isn't already registered (an upgrade may leave
|
||||
# it in place). "nssm install" on an existing service errors otherwise.
|
||||
$exists = Get-Service -Name "VantageAgent" -ErrorAction SilentlyContinue
|
||||
if (-not $exists) {
|
||||
Invoke-Native -File $nssm -Arguments @("install", "VantageAgent", $exe)
|
||||
} else {
|
||||
Write-Log "VantageAgent service already exists - updating binary path"
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "Application", $exe)
|
||||
}
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "Start", "SERVICE_AUTO_START")
|
||||
Invoke-Native -File $nssm -Arguments @("start", "VantageAgent")
|
||||
|
||||
# Redirect service stdout/stderr to log files (nssm discards them otherwise)
|
||||
# with online rotation at ~1MB.
|
||||
$outLog = Join-Path $logDir "agent-stdout.log"
|
||||
$errLog = Join-Path $logDir "agent-stderr.log"
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "AppStdout", $outLog)
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "AppStderr", $errLog)
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "AppStdoutCreationDisposition", "4")
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "AppStderrCreationDisposition", "4")
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "AppRotateFiles", "1")
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "AppRotateOnline", "1")
|
||||
Invoke-Native -File $nssm -Arguments @("set", "VantageAgent", "AppRotateBytes", "1048576")
|
||||
|
||||
# restart (not just start) so an upgrade picks up the new binary
|
||||
Invoke-NativeSoft -File $nssm -Arguments @("restart", "VantageAgent")
|
||||
|
||||
Write-Log "=== setup ok ==="
|
||||
exit 0
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?define Version = "0.0.0.0" ?>
|
||||
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
|
||||
<Package Name="Vantage Agent" Manufacturer="Vantage"
|
||||
Version="1.0.0.0" UpgradeCode="7d1e6d2c-2a5f-4b3e-9c3a-8a1b2c3d4e5f"
|
||||
Version="$(var.Version)" UpgradeCode="7d1e6d2c-2a5f-4b3e-9c3a-8a1b2c3d4e5f"
|
||||
Scope="perMachine">
|
||||
<MajorUpgrade DowngradeErrorMessage="A newer version is already installed." />
|
||||
<MediaTemplate EmbedCab="yes" />
|
||||
|
||||
Reference in New Issue
Block a user