1
0
mirror of https://github.com/rancher/os.git synced 2025-08-11 03:22:49 +00:00

Add prompting to reboot

This commit is contained in:
Darren Shepherd 2015-03-20 11:34:34 -07:00
parent 2f36ddd814
commit 0aeda8d1b0

View File

@ -1,6 +1,7 @@
package control package control
import ( import (
"bufio"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -137,7 +138,19 @@ func osUpgrade(c *cli.Context) {
startUpgradeContainer(image, c.Bool("stage"), c.Bool("force")) startUpgradeContainer(image, c.Bool("stage"), c.Bool("force"))
} }
func yes(in *bufio.Reader, question string) bool {
fmt.Printf("%s [y/N]: ", question)
line, err := in.ReadString('\n')
if err != nil {
log.Fatal(err)
}
return strings.ToLower(line[0:1]) == "y"
}
func startUpgradeContainer(image string, stage, force bool) { func startUpgradeContainer(image string, stage, force bool) {
in := bufio.NewReader(os.Stdin)
container := docker.NewContainer(config.DOCKER_SYSTEM_HOST, &config.ContainerConfig{ container := docker.NewContainer(config.DOCKER_SYSTEM_HOST, &config.ContainerConfig{
Cmd: "--name=os-upgrade " + Cmd: "--name=os-upgrade " +
"--rm " + "--rm " +
@ -152,17 +165,11 @@ func startUpgradeContainer(image string, stage, force bool) {
log.Fatal(container.Err) log.Fatal(container.Err)
} }
if !stage { fmt.Printf("Upgrading to %s\n", image)
fmt.Printf("Upgrading to %s : %v\n", image, stage)
if !force {
fmt.Print("Continue [y/N] ")
one := make([]byte, 1, 1)
_, err := os.Stdin.Read(one)
if err != nil {
log.Fatal(err)
}
if string(one) != "Y" && string(one) != "y" { if !stage {
if !force {
if !yes(in, "Continue") {
os.Exit(1) os.Exit(1)
} }
} }
@ -198,9 +205,12 @@ func startUpgradeContainer(image string, stage, force bool) {
} }
if exit == 0 { if exit == 0 {
log.Info("Rebooting") if force || yes(in, "Continue with reboot") {
power.Reboot() log.Info("Rebooting")
power.Reboot()
}
} else { } else {
log.Error("Upgrade failed")
os.Exit(exit) os.Exit(exit)
} }
} }