fix: exit agent when exec fails after binary replacement during auto-update

When syscall.Exec() fails after the binary has already been atomically
replaced on disk, the old process would log an error and keep running
indefinitely with stale code. The next update check (1 hour later) sees
the on-disk version matches the server and skips the update — so the
restart is never retried.

Now the agent exits with code 1 when this happens, allowing systemd (or
any service manager) to restart it with the new binary. This fixes the
"temperature broken after each upgrade" reports where users had to
manually reinstall the agent after every Pulse server upgrade.

Fixes #1247
This commit is contained in:
rcourtman 2026-02-11 14:26:14 +00:00
parent 2fb6ebc25f
commit 6f156cd211
2 changed files with 9 additions and 1 deletions

View file

@ -1 +1 @@
5.1.8
5.1.9

View file

@ -207,6 +207,14 @@ func (u *Updater) CheckAndUpdate(ctx context.Context) {
if err := u.performUpdateFn(ctx); err != nil {
u.logger.Error().Err(err).Msg("Failed to self-update agent")
// If the binary was replaced but exec failed, the old process is still
// running with a stale binary. Exit so systemd restarts us with the
// new binary. The "failed to restart" error comes from restartProcess()
// which is called AFTER the binary is atomically replaced on disk.
if strings.Contains(err.Error(), "failed to restart") {
u.logger.Error().Msg("Binary replaced but exec failed - exiting so service manager restarts with new binary")
os.Exit(1)
}
return
}