mirror of
https://github.com/rancher/os.git
synced 2025-07-31 22:47:16 +00:00
Merge pull request #2138 from vancluever/shutdown-reboot-arg-fix
cmd/power: Set correct container name and ensure full command executed
This commit is contained in:
commit
d520ef1a1b
@ -38,13 +38,13 @@ func runDocker(name string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := []string{name}
|
cmd := os.Args
|
||||||
containerName := strings.TrimPrefix(strings.Join(strings.Split(name, "/"), "-"), "-")
|
|
||||||
|
|
||||||
if name == "" {
|
if name == "" {
|
||||||
name = filepath.Base(os.Args[0])
|
name = filepath.Base(os.Args[0])
|
||||||
cmd = os.Args
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
containerName := strings.TrimPrefix(strings.Join(strings.Split(name, "/"), "-"), "-")
|
||||||
|
|
||||||
existing, err := client.ContainerInspect(context.Background(), containerName)
|
existing, err := client.ContainerInspect(context.Background(), containerName)
|
||||||
if err == nil && existing.ID != "" {
|
if err == nil && existing.ID != "" {
|
||||||
|
@ -84,7 +84,7 @@ func Shutdown() {
|
|||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
app.Flags = append(app.Flags, cli.BoolFlag{
|
app.Flags = append(app.Flags, cli.BoolFlag{
|
||||||
Name: "H, halt",
|
Name: "H, h, halt",
|
||||||
Usage: "halt the machine",
|
Usage: "halt the machine",
|
||||||
Destination: &haltFlag,
|
Destination: &haltFlag,
|
||||||
})
|
})
|
||||||
@ -197,7 +197,12 @@ func shutdown(c *cli.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeArg := c.Args().Get(0)
|
timeArg := c.Args().Get(0)
|
||||||
if c.App.Name == "shutdown" && timeArg != "" {
|
// We may be called via an absolute path, so check that now and make sure we
|
||||||
|
// don't pass the wrong app name down. Aside from the logic in the immediate
|
||||||
|
// context here, the container name is derived from how we were called and
|
||||||
|
// cannot contain slashes.
|
||||||
|
appName := filepath.Base(c.App.Name)
|
||||||
|
if appName == "shutdown" && timeArg != "" {
|
||||||
if timeArg != "now" {
|
if timeArg != "now" {
|
||||||
err := fmt.Errorf("Sorry, can't parse '%s' as time value (only 'now' supported)", timeArg)
|
err := fmt.Errorf("Sorry, can't parse '%s' as time value (only 'now' supported)", timeArg)
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
@ -206,7 +211,7 @@ func shutdown(c *cli.Context) error {
|
|||||||
// TODO: if there are more params, LOG them
|
// TODO: if there are more params, LOG them
|
||||||
}
|
}
|
||||||
|
|
||||||
reboot(c.App.Name, forceFlag, powerCmd)
|
reboot(appName, forceFlag, powerCmd)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user