func checkForUpdates() { checkTicker := time.Tick(checkFrequency) for range checkTicker { log.Println("Checking for updates..") update, err := cr.GetUpdate(instanceID, appID, groupID, currentVersion) if err != nil { log.Printf("\t- No updates (error: %v)\n", err) continue } log.Println("\t- Updates available!") log.Println("\t- Downloading update package..") cr.EventDownloadStarted(instanceID, appID, groupID) downloadPackage(update.URL, update.Filename) log.Println("\t- Update package downloaded") cr.EventDownloadFinished(instanceID, appID, groupID) log.Println("\t- Update completed successfully :)") cr.EventUpdateSucceeded(instanceID, appID, groupID) log.Println("\t- Restarting server using new package") syscall.Kill(syscall.Getpid(), syscall.SIGUSR2) break } }
func (u *Updater) reportSuccessfulUpdate() { trackFile := u.getTrackFile(u.a.Version) if _, err := os.Stat(trackFile); os.IsNotExist(err) { return } if err := cr.EventUpdateSucceeded(u.a.InstanceID, u.a.AppID, u.a.GroupID); err != nil { logger.Error("reportSuccessfulUpdate failed", "error", err) return } logger.Info("update succesfully deployed", "version", u.a.Version) if err := os.Remove(trackFile); err != nil { logger.Error("Error removing tracking file", "version", u.a.Version, "error", err) } }