2015-03-07 03:32:16 +08:00
|
|
|
package main
|
|
|
|
|
2015-03-13 12:45:43 +08:00
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
2015-03-19 11:22:21 +08:00
|
|
|
"github.com/docker/libcontainer"
|
2015-03-13 12:45:43 +08:00
|
|
|
"github.com/docker/libcontainer/utils"
|
|
|
|
)
|
2015-03-07 03:32:16 +08:00
|
|
|
|
|
|
|
var restoreCommand = cli.Command{
|
|
|
|
Name: "restore",
|
|
|
|
Usage: "restore a container from a previous checkpoint",
|
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{Name: "id", Value: "nsinit", Usage: "specify the ID for a container"},
|
|
|
|
},
|
|
|
|
Action: func(context *cli.Context) {
|
|
|
|
container, err := getContainer(context)
|
|
|
|
if err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
2015-03-19 11:22:21 +08:00
|
|
|
process := &libcontainer.Process{
|
|
|
|
Stdin: os.Stdin,
|
|
|
|
Stdout: os.Stdout,
|
|
|
|
Stderr: os.Stderr,
|
|
|
|
}
|
|
|
|
//rootuid, err := config.HostUID()
|
|
|
|
//if err != nil {
|
2015-03-25 22:59:20 +08:00
|
|
|
//fatal(err)
|
2015-03-19 11:22:21 +08:00
|
|
|
//}
|
2015-03-25 22:59:20 +08:00
|
|
|
rootuid := 0 // XXX
|
2015-03-19 11:22:21 +08:00
|
|
|
tty, err := newTty(context, process, rootuid)
|
|
|
|
if err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
if err := tty.attach(process); err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
err = container.Restore(process)
|
2015-03-13 12:45:43 +08:00
|
|
|
if err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
2015-03-19 11:22:21 +08:00
|
|
|
go handleSignals(process, tty)
|
2015-03-13 12:45:43 +08:00
|
|
|
status, err := process.Wait()
|
|
|
|
if err != nil {
|
|
|
|
exitError, ok := err.(*exec.ExitError)
|
|
|
|
if ok {
|
|
|
|
status = exitError.ProcessState
|
|
|
|
} else {
|
|
|
|
container.Destroy()
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if err := container.Destroy(); err != nil {
|
2015-03-07 03:32:16 +08:00
|
|
|
fatal(err)
|
|
|
|
}
|
2015-03-13 12:45:43 +08:00
|
|
|
os.Exit(utils.ExitStatus(status.Sys().(syscall.WaitStatus)))
|
2015-03-07 03:32:16 +08:00
|
|
|
},
|
|
|
|
}
|