Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *confi
if err != nil {
logrus.Error(err)
}
if status == libcontainer.Running {
fatal(fmt.Errorf("Container with id %s already running", context.GlobalString("id")))
cerr := handleContainerstatus(status, container, context)
if cerr != nil {
return -1, cerr
}
// ensure that the container is always removed if we were the process
// that created it.
Expand Down Expand Up @@ -143,6 +144,21 @@ func restoreContainer(context *cli.Context, spec *specs.LinuxSpec, config *confi
return handler.forward(process)
}

func handleContainerstatus(status libcontainer.Status, container libcontainer.Container, context *cli.Context) error {
switch status {
case libcontainer.Running:
return fmt.Errorf("Container with id %s already running", context.GlobalString("id"))
case libcontainer.Destroyed:
// Ensure to clean/destroy the container as the container id got created during restore startup
dest := filepath.Join(context.GlobalString("root"), context.GlobalString("id"))
if errVal := os.RemoveAll(dest); errVal != nil {
logrus.Error(errVal)
}
return fmt.Errorf("Container with id %s does not exists", context.GlobalString("id"))
}
return nil
}

func criuOptions(context *cli.Context) *libcontainer.CriuOpts {
imagePath := getCheckpointImagePath(context)
if err := os.MkdirAll(imagePath, 0655); err != nil {
Expand Down