コード例 #1
0
ファイル: update.go プロジェクト: pulcy/gluon
func updateMachine(member service.ClusterMember, flags UpdateFlags, log *logging.Logger) error {
	askConfirmation := flags.AskConfirmation
	log.Infof("Updating %s...", member.ClusterIP)

	// Extract gluon binary
	cmd := fmt.Sprintf("docker run --rm -v /home/core/bin/:/destination/ %s", flags.GluonImage)
	if _, err := runRemoteCommand(member, flags.UserName, log, cmd, "", false); err != nil {
		return maskAny(err)
	}

	// Update image version on disk
	if _, err := runRemoteCommand(member, flags.UserName, log, "sudo tee /etc/pulcy/gluon-image", flags.GluonImage, false); err != nil {
		return maskAny(err)
	}

	// Setup new gluon version
	if _, err := runRemoteCommand(member, flags.UserName, log, "sudo systemctl restart gluon", "", false); err != nil {
		return maskAny(err)
	}

	// Reboot if needed
	if flags.Reboot {
		log.Infof("Rebooting %s...", member.ClusterIP)
		runRemoteCommand(member, flags.UserName, log, "sudo reboot -f", "", true)
		time.Sleep(time.Second * 15)
		if err := waitUntilMachineUp(member, flags, log); err != nil {
			return maskAny(err)
		}
		if !member.EtcdProxy {
			log.Warningf("Core machine %s is back up, check services", member.ClusterIP)
			askConfirmation = true
		} else {
			log.Infof("Machine %s is back up", member.ClusterIP)
		}
	}

	if askConfirmation {
		confirm("Can we continue?")
	}

	return nil
}