feat(daemon): auto-apply upgrades when server signals (0.9.6)
OnUpgrade now downloads + replaces the binary and exits in a background goroutine; the service supervisor (systemd Restart=always) respawns on the new version. Removes the "run unarr update" manual step after pressing the web's Force update button.
This commit is contained in:
parent
88316e7017
commit
834c58c25a
3 changed files with 50 additions and 4 deletions
17
CHANGELOG.md
17
CHANGELOG.md
|
|
@ -5,6 +5,23 @@ All notable changes to this project will be documented in this file.
|
||||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
||||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||||
|
|
||||||
|
## [0.9.6] - 2026-05-26
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- **auto-upgrade**: when the web flags the agent for upgrade
|
||||||
|
(`POST /api/internal/agent/upgrade` or the "Force update now" button),
|
||||||
|
the daemon now downloads and replaces the binary in-place, then exits so
|
||||||
|
the service supervisor (`systemd Restart=always` on Linux, the equivalent
|
||||||
|
on macOS/Windows) respawns on the new version. No `unarr update` step
|
||||||
|
required from the user. Still opt-in — only fires when the server sends
|
||||||
|
the upgrade signal.
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- The `OnUpgrade` daemon callback no longer just logs `run unarr self-update`;
|
||||||
|
it now triggers the actual upgrade in a background goroutine.
|
||||||
|
|
||||||
## [0.9.5] - 2026-05-26
|
## [0.9.5] - 2026-05-26
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/torrentclaw/unarr/internal/upgrade"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DaemonConfig holds daemon runtime settings.
|
// DaemonConfig holds daemon runtime settings.
|
||||||
|
|
@ -231,10 +233,12 @@ func (d *Daemon) Run(ctx context.Context) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
d.sync.OnUpgrade = func(version string) {
|
d.sync.OnUpgrade = func(version string) {
|
||||||
if version != d.lastNotifiedVersion {
|
if version == d.lastNotifiedVersion {
|
||||||
d.lastNotifiedVersion = version
|
return
|
||||||
log.Printf("New version available: %s (run `unarr self-update` to upgrade)", version)
|
|
||||||
}
|
}
|
||||||
|
d.lastNotifiedVersion = version
|
||||||
|
log.Printf("[upgrade] new version available: %s — applying auto-upgrade", version)
|
||||||
|
go d.applyAutoUpgrade(version)
|
||||||
}
|
}
|
||||||
d.sync.OnScan = func() {
|
d.sync.OnScan = func() {
|
||||||
log.Printf("Library scan requested by server")
|
log.Printf("Library scan requested by server")
|
||||||
|
|
@ -281,6 +285,31 @@ func (d *Daemon) Deregister() {
|
||||||
RemoveState()
|
RemoveState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// applyAutoUpgrade downloads the target version and exits so the service
|
||||||
|
// supervisor (systemd Restart=always on Linux) respawns on the new binary.
|
||||||
|
// Triggered by the server's upgrade signal — opt-in flag set by the user from
|
||||||
|
// the web UI; the daemon never auto-upgrades on a passive version bump.
|
||||||
|
func (d *Daemon) applyAutoUpgrade(targetVersion string) {
|
||||||
|
currentClean := strings.TrimPrefix(d.cfg.Version, "v")
|
||||||
|
upgrader := &upgrade.Upgrader{
|
||||||
|
CurrentVersion: currentClean,
|
||||||
|
OnProgress: func(msg string) {
|
||||||
|
log.Printf("[upgrade] %s", msg)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
result := upgrader.Execute(ctx, targetVersion)
|
||||||
|
if !result.Success {
|
||||||
|
log.Printf("[upgrade] auto-upgrade failed: %v", result.Error)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
log.Printf("[upgrade] upgraded v%s → v%s; exiting so service supervisor restarts on new binary",
|
||||||
|
result.OldVersion, result.NewVersion)
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
// isTransientError returns true for errors worth retrying (429, 5xx, network).
|
// isTransientError returns true for errors worth retrying (429, 5xx, network).
|
||||||
func isTransientError(err error) bool {
|
func isTransientError(err error) bool {
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
// Version is the CLI version. Overridden by goreleaser ldflags at release time.
|
// Version is the CLI version. Overridden by goreleaser ldflags at release time.
|
||||||
var Version = "0.9.5"
|
var Version = "0.9.6"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue