Example #1
0
File: wait.go Project: jgatkinsn/os
func Main() {
	_, err := docker.NewClient(config.DOCKER_HOST)
	if err != nil {
		logrus.Errorf("Failed to conect to Docker")
		os.Exit(1)
	}

	logrus.Infof("Docker is ready")
}
Example #2
0
File: os.go Project: jgatkinsn/os
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)
		}
	}
}