Delete: exit with non zero if one of the containers encountered an error

Signed-off-by: Wang Long <long.wanglong@huawei.com>
This commit is contained in:
Wang Long 2016-09-27 17:50:13 +08:00
parent 45c30e75ab
commit 7e38b37e7c
1 changed files with 10 additions and 0 deletions

View File

@ -45,6 +45,7 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
},
},
Action: func(context *cli.Context) error {
hasError := false
if !context.Args().Present() {
return fmt.Errorf("runc: \"delete\" requires a minimum of 1 argument")
}
@ -65,11 +66,13 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
}
fmt.Fprintf(os.Stderr, "container %s is not exist\n", id)
}
hasError = true
continue
}
s, err := container.Status()
if err != nil {
fmt.Fprintf(os.Stderr, "status for %s: %v\n", id, err)
hasError = true
continue
}
switch s {
@ -79,18 +82,25 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
err := killContainer(container)
if err != nil {
fmt.Fprintf(os.Stderr, "kill container %s: %v\n", id, err)
hasError = true
}
default:
if context.Bool("force") {
err := killContainer(container)
if err != nil {
fmt.Fprintf(os.Stderr, "kill container %s: %v\n", id, err)
hasError = true
}
} else {
fmt.Fprintf(os.Stderr, "cannot delete container %s that is not stopped: %s\n", id, s)
hasError = true
}
}
}
if hasError {
return fmt.Errorf("one or more of the container deletions failed")
}
return nil
},
}