Ejemplo n.º 1
0
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
	}
}
Ejemplo n.º 2
0
func (u *Updater) processUpdate(update *cr.Update) error {
	logger.Info("downloading artifact", "filename", update.Filename, "version", update.Version)
	cr.EventDownloadStarted(u.a.InstanceID, u.a.AppID, u.a.GroupID)

	artifactPath, err := u.a.Download(update)
	if err != nil {
		logger.Error("artifact download failed", "filename", update.Filename, "version", update.Version, "error", err)
		return err
	}

	logger.Info("artifact downloaded", "artifactPath", artifactPath)
	cr.EventDownloadFinished(u.a.InstanceID, u.a.AppID, u.a.GroupID)

	logger.Info("installing update", "version", update.Version)
	if err := u.a.Install(artifactPath); err != nil {
		logger.Error("install update failed", "artifactPath", artifactPath)
		return err
	}
	logger.Info("update installed", "version", update.Version)

	if err := u.trackInstalledUpdate(update); err != nil {
		logger.Error("trackInstalledUpdate failed", "version", update.Version, "error", err)
	}

	logger.Info("sending signal to process now to restart..", "version", update.Version)
	syscall.Kill(syscall.Getpid(), u.signal)

	return nil
}