2016-04-13 05:41:09 +08:00
|
|
|
// +build !solaris
|
|
|
|
|
2016-01-12 08:57:18 +08:00
|
|
|
package main
|
|
|
|
|
2016-03-29 04:27:28 +08:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
2016-05-17 08:04:49 +08:00
|
|
|
"syscall"
|
2016-03-29 04:27:28 +08:00
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
"github.com/opencontainers/runc/libcontainer"
|
|
|
|
)
|
2016-01-12 08:57:18 +08:00
|
|
|
|
|
|
|
var deleteCommand = cli.Command{
|
|
|
|
Name: "delete",
|
|
|
|
Usage: "delete any resources held by the container often used with detached containers",
|
2016-02-11 01:30:06 +08:00
|
|
|
ArgsUsage: `<container-id>
|
|
|
|
|
|
|
|
Where "<container-id>" is the name for the instance of the container.
|
2016-05-24 16:59:24 +08:00
|
|
|
|
|
|
|
EXAMPLE:
|
2016-02-11 01:30:06 +08:00
|
|
|
For example, if the container id is "ubuntu01" and runc list currently shows the
|
|
|
|
status of "ubuntu01" as "destroyed" the following will delete resources held for
|
|
|
|
"ubuntu01" removing "ubuntu01" from the runc list of containers:
|
|
|
|
|
|
|
|
# runc delete ubuntu01`,
|
2016-05-10 13:58:09 +08:00
|
|
|
Action: func(context *cli.Context) error {
|
2016-01-12 08:57:18 +08:00
|
|
|
container, err := getContainer(context)
|
|
|
|
if err != nil {
|
2016-03-29 04:27:28 +08:00
|
|
|
if lerr, ok := err.(libcontainer.Error); ok && lerr.Code() == libcontainer.ContainerNotExists {
|
|
|
|
// if there was an aborted start or something of the sort then the container's directory could exist but
|
|
|
|
// libcontainer does not see it because the state.json file inside that directory was never created.
|
|
|
|
path := filepath.Join(context.GlobalString("root"), context.Args().First())
|
2016-05-10 13:58:09 +08:00
|
|
|
if err := os.RemoveAll(path); err != nil {
|
|
|
|
return err
|
2016-03-29 04:27:28 +08:00
|
|
|
}
|
|
|
|
}
|
2016-05-10 13:58:09 +08:00
|
|
|
return nil
|
2016-01-12 08:57:18 +08:00
|
|
|
}
|
2016-05-17 08:04:49 +08:00
|
|
|
s, err := container.Status()
|
|
|
|
if err == nil && s == libcontainer.Created {
|
|
|
|
container.Signal(syscall.SIGKILL)
|
|
|
|
}
|
2016-01-12 08:57:18 +08:00
|
|
|
destroy(container)
|
2016-05-10 13:58:09 +08:00
|
|
|
return nil
|
2016-01-12 08:57:18 +08:00
|
|
|
},
|
|
|
|
}
|