Add autoUpgrade coroutine (fixes #727)

Conflicts:
	internal/config/config.go
This commit is contained in:
Audrius Butkevicius
2014-09-28 21:19:54 +01:00
parent aaec3330a9
commit 77fcb52b6a
2 changed files with 54 additions and 16 deletions
+37
View File
@@ -620,6 +620,10 @@ nextRepo:
go standbyMonitor()
}
if cfg.Options.AutoUpgradeIntervalH > 0 {
go autoUpgrade()
}
events.Default.Log(events.StartupComplete, nil)
go generateEvents()
@@ -1172,3 +1176,36 @@ func standbyMonitor() {
now = time.Now()
}
}
func autoUpgrade() {
var skipped bool
interval := time.Duration(cfg.Options.AutoUpgradeIntervalH) * time.Hour
for {
if skipped {
time.Sleep(interval)
} else {
skipped = true
}
rel, err := upgrade.LatestRelease(strings.Contains(Version, "-beta"))
if err != nil {
l.Warnln("Automatic upgrade:", err)
continue
}
if upgrade.CompareVersions(rel.Tag, Version) <= 0 {
continue
}
l.Infof("Automatic upgrade (current %q < latest %q)", Version, rel.Tag)
err = upgrade.UpgradeTo(rel, GoArchExtra)
if err != nil {
l.Warnln("Automatic upgrade:", err)
continue
}
l.Warnf("Automatically upgraded to version %q. Restarting in 1 minute.", rel.Tag)
time.Sleep(time.Minute)
stop <- exitUpgrading
return
}
}