mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
Add --force flag to runc delete
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
@@ -13,6 +13,18 @@ import (
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
func killContainer(container libcontainer.Container) error {
|
||||
container.Signal(syscall.SIGKILL)
|
||||
for i := 0; i < 100; i++ {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if err := container.Signal(syscall.Signal(0)); err != nil {
|
||||
destroy(container)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("container init still running")
|
||||
}
|
||||
|
||||
var deleteCommand = cli.Command{
|
||||
Name: "delete",
|
||||
Usage: "delete any resources held by the container often used with detached containers",
|
||||
@@ -23,9 +35,15 @@ Where "<container-id>" is the name for the instance of the container.
|
||||
EXAMPLE:
|
||||
For example, if the container id is "ubuntu01" and runc list currently shows the
|
||||
status of "ubuntu01" as "stopped" the following will delete resources held for
|
||||
"ubuntu01" removing "ubuntu01" from the runc list of containers:
|
||||
|
||||
"ubuntu01" removing "ubuntu01" from the runc list of containers:
|
||||
|
||||
# runc delete ubuntu01`,
|
||||
Flags: []cli.Flag{
|
||||
cli.BoolFlag{
|
||||
Name: "force, f",
|
||||
Usage: "Forcibly kills the container if it is still running",
|
||||
},
|
||||
},
|
||||
Action: func(context *cli.Context) error {
|
||||
container, err := getContainer(context)
|
||||
if err != nil {
|
||||
@@ -47,16 +65,11 @@ status of "ubuntu01" as "stopped" the following will delete resources held for
|
||||
case libcontainer.Stopped:
|
||||
destroy(container)
|
||||
case libcontainer.Created:
|
||||
container.Signal(syscall.SIGKILL)
|
||||
for i := 0; i < 100; i++ {
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
if err := container.Signal(syscall.Signal(0)); err != nil {
|
||||
destroy(container)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("container init still running")
|
||||
return killContainer(container)
|
||||
default:
|
||||
if context.Bool("force") {
|
||||
return killContainer(container)
|
||||
}
|
||||
return fmt.Errorf("cannot delete container that is not stopped: %s", s)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user