1
0
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:
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
}
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 != "" {

View File

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