Files
Pulse/scripts/install.ps1
rcourtman ae3b78d661 fix: propagate unified agent version and improve legacy cleanup
Issues found during scenario testing:

1. Version propagation: The hostagent and dockeragent packages were
   reporting their own Version (0.1.0-dev) instead of the unified
   agent's version. Added AgentVersion config field to pass the
   parent's version down.

2. macOS legacy cleanup: The install.sh script was missing cleanup
   for pulse-docker-agent on macOS.

3. Windows legacy cleanup: The install.ps1 script was missing cleanup
   for legacy PulseHostAgent and PulseDockerAgent services.

These fixes ensure:
- Unified agent reports consistent version across host/docker metrics
- Legacy agents are properly removed on all platforms during upgrade
- Users migrating from legacy agents get a clean transition
2025-11-25 23:39:10 +00:00

119 lines
4.2 KiB
PowerShell

# Pulse Unified Agent Installer (Windows)
# Usage:
# irm http://pulse/install.ps1 | iex
# $env:PULSE_URL="..."; $env:PULSE_TOKEN="..."; irm ... | iex
param (
[string]$Url = $env:PULSE_URL,
[string]$Token = $env:PULSE_TOKEN,
[string]$Interval = "30s",
[bool]$EnableHost = $true,
[bool]$EnableDocker = $false,
[bool]$Insecure = $false,
[bool]$Uninstall = $false
)
$ErrorActionPreference = "Stop"
$AgentName = "PulseAgent"
$BinaryName = "pulse-agent.exe"
$InstallDir = "C:\Program Files\Pulse"
$LogFile = "$env:ProgramData\Pulse\pulse-agent.log"
# --- Uninstall Logic ---
if ($Uninstall) {
Write-Host "Uninstalling $AgentName..." -ForegroundColor Cyan
if (Get-Service $AgentName -ErrorAction SilentlyContinue) {
Stop-Service $AgentName -Force -ErrorAction SilentlyContinue
sc.exe delete $AgentName | Out-Null
}
Remove-Item "$InstallDir\$BinaryName" -Force -ErrorAction SilentlyContinue
Write-Host "Uninstallation complete." -ForegroundColor Green
Exit 0
}
# --- Validation ---
if ([string]::IsNullOrWhiteSpace($Url) -or [string]::IsNullOrWhiteSpace($Token)) {
Write-Error "Missing required parameters: Url and Token. Set PULSE_URL/PULSE_TOKEN env vars or pass arguments."
Exit 1
}
# --- Download ---
# Determine architecture
$Arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
$ArchParam = "windows-$Arch"
$DownloadUrl = "$Url/download/pulse-agent?arch=$ArchParam"
Write-Host "Downloading agent from $DownloadUrl..." -ForegroundColor Cyan
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Force -Path $InstallDir | Out-Null
}
$DestPath = "$InstallDir\$BinaryName"
try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $DestPath -UseBasicParsing
} catch {
Write-Host "Failed to download agent: $_" -ForegroundColor Red
# Try to show a popup if running in a GUI environment
try {
Add-Type -AssemblyName System.Windows.Forms
[System.Windows.Forms.MessageBox]::Show("Failed to download agent.`n`n$_", "Pulse Installation Failed", [System.Windows.Forms.MessageBoxButtons]::OK, [System.Windows.Forms.MessageBoxIcon]::Error) | Out-Null
} catch {
# Ignore if GUI not available
}
Write-Host ""
Write-Host "Press Enter to exit..." -ForegroundColor Yellow
Read-Host
Exit 1
}
# --- Legacy Cleanup ---
# Remove old agents if they exist to prevent conflicts
Write-Host "Checking for legacy agents..." -ForegroundColor Cyan
if (Get-Service "PulseHostAgent" -ErrorAction SilentlyContinue) {
Write-Host "Removing legacy PulseHostAgent..." -ForegroundColor Yellow
Stop-Service "PulseHostAgent" -Force -ErrorAction SilentlyContinue
sc.exe delete "PulseHostAgent" | Out-Null
Remove-Item "C:\Program Files\Pulse\pulse-host-agent.exe" -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
}
if (Get-Service "PulseDockerAgent" -ErrorAction SilentlyContinue) {
Write-Host "Removing legacy PulseDockerAgent..." -ForegroundColor Yellow
Stop-Service "PulseDockerAgent" -Force -ErrorAction SilentlyContinue
sc.exe delete "PulseDockerAgent" | Out-Null
Remove-Item "C:\Program Files\Pulse\pulse-docker-agent.exe" -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 2
}
# --- Service Installation ---
Write-Host "Configuring Windows Service..." -ForegroundColor Cyan
if (Get-Service $AgentName -ErrorAction SilentlyContinue) {
Stop-Service $AgentName -Force -ErrorAction SilentlyContinue
sc.exe delete $AgentName | Out-Null
Start-Sleep -Seconds 2
}
# Build command line args
$Args = "--url `"$Url`" --token `"$Token`" --interval `"$Interval`""
if ($EnableHost) { $Args += " --enable-host" }
if ($EnableDocker) { $Args += " --enable-docker" }
if ($Insecure) { $Args += " --insecure" }
$BinPath = "`"$DestPath`" $Args"
# Create Service
sc.exe create $AgentName binPath= $BinPath start= auto displayname= "Pulse Unified Agent" | Out-Null
sc.exe description $AgentName "Pulse Unified Agent for Host and Docker monitoring" | Out-Null
sc.exe failure $AgentName reset= 86400 actions= restart/5000/restart/5000/restart/5000 | Out-Null
Start-Service $AgentName
Write-Host "Installation complete." -ForegroundColor Green
Write-Host "Service: $AgentName"
Write-Host "Logs: $LogFile"