diff --git a/cmd/pulse-agent/main.go b/cmd/pulse-agent/main.go index b4fd78490..d8033a59c 100644 --- a/cmd/pulse-agent/main.go +++ b/cmd/pulse-agent/main.go @@ -82,6 +82,7 @@ func main() { HostnameOverride: cfg.HostnameOverride, AgentID: cfg.AgentID, // Shared ID? Or separate? Usually separate for now. AgentType: "unified", + AgentVersion: Version, // Pass unified agent version Tags: cfg.Tags, InsecureSkipVerify: cfg.InsecureSkipVerify, LogLevel: cfg.LogLevel, @@ -111,6 +112,7 @@ func main() { HostnameOverride: cfg.HostnameOverride, AgentID: cfg.AgentID, AgentType: "unified", + AgentVersion: Version, // Pass unified agent version InsecureSkipVerify: cfg.InsecureSkipVerify, DisableAutoUpdate: true, // Unified agent handles updates LogLevel: cfg.LogLevel, diff --git a/internal/dockeragent/agent.go b/internal/dockeragent/agent.go index 7cef43aaa..cd0249bf7 100644 --- a/internal/dockeragent/agent.go +++ b/internal/dockeragent/agent.go @@ -48,6 +48,7 @@ type Config struct { HostnameOverride string AgentID string AgentType string // "unified" when running as part of pulse-agent, empty for standalone + AgentVersion string // Version to report; if empty, uses dockeragent.Version InsecureSkipVerify bool DisableAutoUpdate bool Targets []TargetConfig @@ -88,6 +89,7 @@ type Agent struct { daemonHost string runtime RuntimeKind runtimeVer string + agentVersion string supportsSwarm bool httpClients map[bool]*http.Client logger zerolog.Logger @@ -226,12 +228,19 @@ func New(cfg Config) (*Agent, error) { } } + // Use configured version or fall back to package version + agentVersion := cfg.AgentVersion + if agentVersion == "" { + agentVersion = Version + } + agent := &Agent{ cfg: cfg, docker: dockerClient, daemonHost: dockerClient.DaemonHost(), runtime: runtimeKind, runtimeVer: info.ServerVersion, + agentVersion: agentVersion, supportsSwarm: runtimeKind == RuntimeDocker, httpClients: httpClients, logger: *logger, @@ -656,7 +665,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentsdocker.Report, error) { report := agentsdocker.Report{ Agent: agentsdocker.AgentInfo{ ID: agentID, - Version: Version, + Version: a.agentVersion, Type: a.cfg.AgentType, IntervalSeconds: int(a.cfg.Interval / time.Second), }, diff --git a/internal/hostagent/agent.go b/internal/hostagent/agent.go index fe6efc3cd..def8bbb82 100644 --- a/internal/hostagent/agent.go +++ b/internal/hostagent/agent.go @@ -28,6 +28,7 @@ type Config struct { HostnameOverride string AgentID string AgentType string // "unified" when running as part of pulse-agent, empty for standalone + AgentVersion string // Version to report; if empty, uses hostagent.Version Tags []string InsecureSkipVerify bool RunOnce bool @@ -51,6 +52,7 @@ type Agent struct { architecture string machineID string agentID string + agentVersion string interval time.Duration trimmedPulseURL string } @@ -156,6 +158,12 @@ func New(cfg Config) (*Agent, error) { } cfg.Tags = trimmedTags + // Use configured version or fall back to package version + agentVersion := cfg.AgentVersion + if agentVersion == "" { + agentVersion = Version + } + return &Agent{ cfg: cfg, logger: logger, @@ -170,6 +178,7 @@ func New(cfg Config) (*Agent, error) { architecture: arch, machineID: machineID, agentID: agentID, + agentVersion: agentVersion, interval: cfg.Interval, trimmedPulseURL: pulseURL, }, nil @@ -241,7 +250,7 @@ func (a *Agent) buildReport(ctx context.Context) (agentshost.Report, error) { report := agentshost.Report{ Agent: agentshost.AgentInfo{ ID: a.agentID, - Version: Version, + Version: a.agentVersion, Type: a.cfg.AgentType, IntervalSeconds: int(a.interval / time.Second), Hostname: a.hostname, diff --git a/scripts/install.ps1 b/scripts/install.ps1 index f637f2eda..a43d4b1dd 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -70,6 +70,26 @@ try { 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 diff --git a/scripts/install.sh b/scripts/install.sh index 32d421933..fdb256451 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -166,6 +166,12 @@ if [[ "$OS" == "darwin" ]]; then rm -f /Library/LaunchDaemons/com.pulse.host-agent.plist rm -f /usr/local/bin/pulse-host-agent fi + if launchctl list | grep -q "com.pulse.docker-agent"; then + log_warn "Removing legacy com.pulse.docker-agent..." + launchctl unload /Library/LaunchDaemons/com.pulse.docker-agent.plist 2>/dev/null || true + rm -f /Library/LaunchDaemons/com.pulse.docker-agent.plist + rm -f /usr/local/bin/pulse-docker-agent + fi fi # --- Service Installation ---