1
0
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:
niusmallnan 2018-01-23 18:07:57 +08:00 committed by GitHub
commit d520ef1a1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 6 deletions

View File

@ -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 != "" {

View File

@ -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
} }