mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
Remove container root dir from an aborted start
If runc was SIGKILL'd or something happened and the container was not able to start and runc died as well then we could get into the state where `$root/<containerid>` exists but `$root/<containerid>/state.json` does not. This will not allow libcontainer to load the container to call the delete function as it has no data on the container other than its id. We should just remove it in runc so that that system matches what runc sees for the container. Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
package main
|
||||
|
||||
import "github.com/codegangsta/cli"
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/codegangsta/cli"
|
||||
"github.com/opencontainers/runc/libcontainer"
|
||||
)
|
||||
|
||||
var deleteCommand = cli.Command{
|
||||
Name: "delete",
|
||||
@@ -17,6 +23,14 @@ status of "ubuntu01" as "destroyed" the following will delete resources held for
|
||||
Action: func(context *cli.Context) {
|
||||
container, err := getContainer(context)
|
||||
if err != nil {
|
||||
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())
|
||||
if err := os.RemoveAll(path); err == nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
fatal(err)
|
||||
}
|
||||
destroy(container)
|
||||
|
||||
Reference in New Issue
Block a user