1
0
mirror of https://github.com/rancher/os.git synced 2025-09-07 09:42:21 +00:00

Reboot after os upgrade

This commit is contained in:
Darren Shepherd
2015-03-19 15:36:40 -07:00
parent e34c3a5e2d
commit a051b1ad70
2 changed files with 15 additions and 9 deletions

View File

@@ -19,7 +19,7 @@ const (
DOCKER_CGROUPS_FILE = "/proc/self/cgroup" DOCKER_CGROUPS_FILE = "/proc/self/cgroup"
) )
func runDocker() error { func runDocker(name string) error {
if os.ExpandEnv("${IN_DOCKER}") == "true" { if os.ExpandEnv("${IN_DOCKER}") == "true" {
return nil return nil
} }
@@ -29,7 +29,13 @@ func runDocker() error {
return err return err
} }
name := filepath.Base(os.Args[0]) cmd := []string{name}
if name == "" {
name = filepath.Base(os.Args[0])
cmd = os.Args
}
exiting, err := client.InspectContainer(name) exiting, err := client.InspectContainer(name)
if exiting != nil { if exiting != nil {
err := client.RemoveContainer(dockerClient.RemoveContainerOptions{ err := client.RemoveContainer(dockerClient.RemoveContainerOptions{
@@ -56,7 +62,7 @@ func runDocker() error {
Name: name, Name: name,
Config: &dockerClient.Config{ Config: &dockerClient.Config{
Image: currentContainer.Config.Image, Image: currentContainer.Config.Image,
Cmd: os.Args, Cmd: cmd,
Env: []string{ Env: []string{
"IN_DOCKER=true", "IN_DOCKER=true",
}, },
@@ -98,28 +104,28 @@ func runDocker() error {
return nil return nil
} }
func common() { func common(name string) {
if os.Geteuid() != 0 { if os.Geteuid() != 0 {
log.Fatalf("%s: Need to be root", os.Args[0]) log.Fatalf("%s: Need to be root", os.Args[0])
} }
if err := runDocker(); err != nil { if err := runDocker(name); err != nil {
log.Fatal(err) log.Fatal(err)
} }
} }
func PowerOff() { func PowerOff() {
common() common("poweroff")
reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF) reboot(syscall.LINUX_REBOOT_CMD_POWER_OFF)
} }
func Reboot() { func Reboot() {
common() common("reboot")
reboot(syscall.LINUX_REBOOT_CMD_RESTART) reboot(syscall.LINUX_REBOOT_CMD_RESTART)
} }
func Halt() { func Halt() {
common() common("halt")
reboot(syscall.LINUX_REBOOT_CMD_HALT) reboot(syscall.LINUX_REBOOT_CMD_HALT)
} }

View File

@@ -32,7 +32,7 @@ func Main() {
} }
func shutdown(c *cli.Context) { func shutdown(c *cli.Context) {
common() common("")
reboot := c.String("r") reboot := c.String("r")
poweroff := c.String("h") poweroff := c.String("h")