Skip to content
This repository was archived by the owner on Dec 13, 2018. It is now read-only.

Commit bfb093a

Browse files
bouchercrosbymichael
authored andcommitted
Allow restore to actually exec/create the libcontainer, rather than requiring that one already exists.
Docker-DCO-1.1-Signed-off-by: Ross Boucher <[email protected]> (github: boucher)
1 parent a16d7f1 commit bfb093a

File tree

1 file changed

+46
-6
lines changed

1 file changed

+46
-6
lines changed

nsinit/restore.go

+46-6
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,31 @@ var restoreCommand = cli.Command{
2727
if imagePath == "" {
2828
fatal(fmt.Errorf("The --image-path option isn't specified"))
2929
}
30-
container, err := getContainer(context)
30+
31+
var (
32+
container libcontainer.Container
33+
err error
34+
)
35+
36+
factory, err := loadFactory(context)
37+
if err != nil {
38+
fatal(err)
39+
}
40+
41+
config, err := loadConfig(context)
3142
if err != nil {
3243
fatal(err)
3344
}
45+
46+
created := false
47+
container, err = factory.Load(context.String("id"))
48+
if err != nil {
49+
created = true
50+
if container, err = factory.Create(context.String("id"), config); err != nil {
51+
fatal(err)
52+
}
53+
}
54+
3455
process := &libcontainer.Process{
3556
Stdin: os.Stdin,
3657
Stdout: os.Stdout,
@@ -48,6 +69,8 @@ var restoreCommand = cli.Command{
4869
if err := tty.attach(process); err != nil {
4970
fatal(err)
5071
}
72+
go handleSignals(process, tty)
73+
5174
err = container.Restore(process, &libcontainer.CriuOpts{
5275
ImagesDirectory: imagePath,
5376
WorkDirectory: context.String("work-path"),
@@ -56,25 +79,42 @@ var restoreCommand = cli.Command{
5679
ShellJob: context.Bool("shell-job"),
5780
})
5881
if err != nil {
82+
tty.Close()
83+
if created {
84+
container.Destroy()
85+
}
5986
fatal(err)
6087
}
61-
go handleSignals(process, tty)
88+
6289
status, err := process.Wait()
6390
if err != nil {
6491
exitError, ok := err.(*exec.ExitError)
6592
if ok {
6693
status = exitError.ProcessState
6794
} else {
68-
container.Destroy()
95+
tty.Close()
96+
if created {
97+
container.Destroy()
98+
}
6999
fatal(err)
70100
}
71101
}
72-
ctStatus, err := container.Status()
73-
if ctStatus == libcontainer.Destroyed {
74-
if err := container.Destroy(); err != nil {
102+
103+
if created {
104+
status, err := container.Status()
105+
if err != nil {
106+
tty.Close()
75107
fatal(err)
76108
}
109+
if status != libcontainer.Checkpointed {
110+
if err := container.Destroy(); err != nil {
111+
tty.Close()
112+
fatal(err)
113+
}
114+
}
77115
}
116+
117+
tty.Close()
78118
os.Exit(utils.ExitStatus(status.Sys().(syscall.WaitStatus)))
79119
},
80120
}

0 commit comments

Comments
 (0)