Beispiel #1
0
func runInstall(cfg *config.CloudConfig, image, installType, cloudConfig, device string, force, reboot bool) error {
	in := bufio.NewReader(os.Stdin)

	fmt.Printf("Installing from %s\n", image)

	if !force {
		if !yes(in, "Continue") {
			os.Exit(1)
		}
	}

	if installType == "generic" {
		cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=all-volumes",
			"--entrypoint=/scripts/set-disk-partitions", image, device)
		cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
		if err := cmd.Run(); err != nil {
			return err
		}
	}
	cmd := exec.Command("system-docker", "run", "--net=host", "--privileged", "--volumes-from=user-volumes", image,
		"-d", device, "-t", installType, "-c", cloudConfig)
	cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr
	if err := cmd.Run(); err != nil {
		return err
	}

	if reboot && yes(in, "Continue with reboot") {
		log.Info("Rebooting")
		power.Reboot()
	}

	return nil
}
Beispiel #2
0
func startUpgradeContainer(image string, stage, force, reboot bool) {
	in := bufio.NewReader(os.Stdin)

	container := docker.NewContainer(config.DOCKER_SYSTEM_HOST, &config.ContainerConfig{
		Cmd: "--name=os-upgrade " +
			"--log-driver=json-file " +
			"--rm " +
			"--privileged " +
			"--net=host " +
			image + " " +
			"-t rancher-upgrade " +
			"-r " + config.VERSION,
	}).Stage()

	if container.Err != nil {
		log.Fatal(container.Err)
	}

	if !stage {
		fmt.Printf("Upgrading to %s\n", image)

		if !force {
			if !yes(in, "Continue") {
				os.Exit(1)
			}
		}

		container.Start()
		if container.Err != nil {
			log.Fatal(container.Err)
		}

		client, err := docker.NewClient(config.DOCKER_SYSTEM_HOST)
		if err != nil {
			log.Fatal(err)
		}

		go func() {
			client.Logs(dockerClient.LogsOptions{
				Container:    container.Container.ID,
				OutputStream: os.Stdout,
				ErrorStream:  os.Stderr,
				Follow:       true,
				Stdout:       true,
				Stderr:       true,
			})
		}()

		exit, err := client.WaitContainer(container.Container.ID)
		if err != nil {
			log.Fatal(err)
		}

		if container.Err != nil {
			log.Fatal(container.Err)
		}

		if exit == 0 {
			if reboot && (force || yes(in, "Continue with reboot")) {
				log.Info("Rebooting")
				power.Reboot()
			}
		} else {
			log.Error("Upgrade failed")
			os.Exit(exit)
		}
	}
}