mirror of
https://github.com/rancher/os.git
synced 2025-07-30 22:24:33 +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
|
||||
}
|
||||
|
||||
cmd := []string{name}
|
||||
containerName := strings.TrimPrefix(strings.Join(strings.Split(name, "/"), "-"), "-")
|
||||
cmd := os.Args
|
||||
|
||||
if name == "" {
|
||||
name = filepath.Base(os.Args[0])
|
||||
cmd = os.Args
|
||||
}
|
||||
|
||||
containerName := strings.TrimPrefix(strings.Join(strings.Split(name, "/"), "-"), "-")
|
||||
|
||||
existing, err := client.ContainerInspect(context.Background(), containerName)
|
||||
if err == nil && existing.ID != "" {
|
||||
|
@ -84,7 +84,7 @@ func Shutdown() {
|
||||
})
|
||||
} else {
|
||||
app.Flags = append(app.Flags, cli.BoolFlag{
|
||||
Name: "H, halt",
|
||||
Name: "H, h, halt",
|
||||
Usage: "halt the machine",
|
||||
Destination: &haltFlag,
|
||||
})
|
||||
@ -197,7 +197,12 @@ func shutdown(c *cli.Context) error {
|
||||
}
|
||||
|
||||
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" {
|
||||
err := fmt.Errorf("Sorry, can't parse '%s' as time value (only 'now' supported)", timeArg)
|
||||
log.Error(err)
|
||||
@ -206,7 +211,7 @@ func shutdown(c *cli.Context) error {
|
||||
// TODO: if there are more params, LOG them
|
||||
}
|
||||
|
||||
reboot(c.App.Name, forceFlag, powerCmd)
|
||||
reboot(appName, forceFlag, powerCmd)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user