Exemplo n.º 1
0
Arquivo: os.go Projeto: datawolf/os
func startUpgradeContainer(image string, stage, force, reboot, kexec bool) error {
	in := bufio.NewReader(os.Stdin)

	command := []string{
		"-t", "rancher-upgrade",
		"-r", config.VERSION,
	}

	if kexec {
		command = append(command, "-k")
	}

	container, err := compose.CreateService(nil, "os-upgrade", &project.ServiceConfig{
		LogDriver:  "json-file",
		Privileged: true,
		Net:        "host",
		Pid:        "host",
		Image:      image,
		Labels: project.NewSliceorMap(map[string]string{
			config.SCOPE: config.SYSTEM,
		}),
		Command: project.NewCommand(command...),
	})
	if err != nil {
		return err
	}

	if err := container.Pull(); err != nil {
		return err
	}

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

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

		if err := container.Up(); err != nil {
			return err
		}

		if err := container.Log(); err != nil {
			return err
		}

		if err := container.Delete(); err != nil {
			return err
		}

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

	return nil
}
Exemplo n.º 2
0
func consoleSwitch(c *cli.Context) error {
	if len(c.Args()) != 1 {
		log.Fatal("Must specify exactly one console to switch to")
	}
	newConsole := c.Args()[0]

	cfg := config.LoadConfig()
	if newConsole == cfg.Rancher.Console {
		log.Warnf("Console is already set to %s", newConsole)
	}

	if !c.Bool("force") {
		in := bufio.NewReader(os.Stdin)
		fmt.Println("Switching consoles will destroy the current console container and restart Docker.")
		fmt.Println("Note: You will also be logged out.")
		if !yes(in, "Continue") {
			return nil
		}
	}

	if newConsole != "default" {
		if err := compose.StageServices(cfg, newConsole); err != nil {
			return err
		}
	}

	service, err := compose.CreateService(nil, "switch-console", &composeConfig.ServiceConfigV1{
		LogDriver:  "json-file",
		Privileged: true,
		Net:        "host",
		Pid:        "host",
		Image:      fmt.Sprintf("rancher/os-base:%s", config.VERSION),
		Labels: map[string]string{
			config.SCOPE: config.SYSTEM,
		},
		Command:     []string{"/usr/bin/switch-console", newConsole},
		VolumesFrom: []string{"all-volumes"},
	})
	if err != nil {
		return err
	}

	if err = service.Delete(context.Background(), options.Delete{}); err != nil {
		return err
	}
	if err = service.Up(context.Background(), options.Up{}); err != nil {
		return err
	}
	return service.Log(context.Background(), true)
}
Exemplo n.º 3
0
Arquivo: os.go Projeto: carriercomm/os
func startUpgradeContainer(image string, stage, force, reboot, kexec bool, kernelArgs string) error {
	in := bufio.NewReader(os.Stdin)

	command := []string{
		"-t", "rancher-upgrade",
		"-r", config.VERSION,
	}

	if kexec {
		command = append(command, "-k")

		kernelArgs = strings.TrimSpace(kernelArgs)
		if kernelArgs != "" {
			command = append(command, "-a", kernelArgs)
		}
	}

	container, err := compose.CreateService(nil, "os-upgrade", &project.ServiceConfig{
		LogDriver:  "json-file",
		Privileged: true,
		Net:        "host",
		Pid:        "host",
		Image:      image,
		Labels: project.NewSliceorMap(map[string]string{
			config.SCOPE: config.SYSTEM,
		}),
		Command: project.NewCommand(command...),
	})
	if err != nil {
		return err
	}

	client, err := docker.NewSystemClient()
	if err != nil {
		return err
	}

	// Only pull image if not found locally
	if _, err := client.InspectImage(image); err != nil {
		if err := container.Pull(); err != nil {
			return err
		}
	}

	if !stage {
		imageSplit := strings.Split(image, ":")
		if len(imageSplit) > 1 && imageSplit[1] == config.VERSION {
			if !force && !yes(in, fmt.Sprintf("Already at version %s. Continue anyways", imageSplit[1])) {
				os.Exit(1)
			}
		} else {
			fmt.Printf("Upgrading to %s\n", image)

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

		// If there is already an upgrade container, delete it
		// Up() should to this, but currently does not due to a bug
		if err := container.Delete(); err != nil {
			return err
		}

		if err := container.Up(); err != nil {
			return err
		}

		if err := container.Log(); err != nil {
			return err
		}

		if err := container.Delete(); err != nil {
			return err
		}

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

	return nil
}