mirror of
https://github.com/rancher/os.git
synced 2025-08-01 15:08:47 +00:00
Add logging and -f to upgrade
This commit is contained in:
parent
4994f4dc9e
commit
932709e3ba
@ -5,6 +5,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
@ -38,6 +39,10 @@ func osSubcommands() []cli.Command {
|
|||||||
Name: "image, i",
|
Name: "image, i",
|
||||||
Usage: "upgrade to a certain image",
|
Usage: "upgrade to a certain image",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "force, f",
|
||||||
|
Usage: "do not prompt for input",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -129,10 +134,10 @@ func osUpgrade(c *cli.Context) {
|
|||||||
log.Fatal("Failed to find latest image")
|
log.Fatal("Failed to find latest image")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startUpgradeContainer(image, c.Bool("stage"))
|
startUpgradeContainer(image, c.Bool("stage"), c.Bool("force"))
|
||||||
}
|
}
|
||||||
|
|
||||||
func startUpgradeContainer(image string, stage bool) {
|
func startUpgradeContainer(image string, stage, force bool) {
|
||||||
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 " +
|
||||||
@ -148,11 +153,56 @@ func startUpgradeContainer(image string, stage bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !stage {
|
if !stage {
|
||||||
container.StartAndWait()
|
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" {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
container.Start()
|
||||||
if container.Err != nil {
|
if container.Err != nil {
|
||||||
log.Fatal(container.Err)
|
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 {
|
||||||
|
log.Info("Rebooting")
|
||||||
power.Reboot()
|
power.Reboot()
|
||||||
|
} else {
|
||||||
|
os.Exit(exit)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user