@@ -27,10 +27,31 @@ var restoreCommand = cli.Command{
27
27
if imagePath == "" {
28
28
fatal (fmt .Errorf ("The --image-path option isn't specified" ))
29
29
}
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 )
31
42
if err != nil {
32
43
fatal (err )
33
44
}
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
+
34
55
process := & libcontainer.Process {
35
56
Stdin : os .Stdin ,
36
57
Stdout : os .Stdout ,
@@ -48,6 +69,8 @@ var restoreCommand = cli.Command{
48
69
if err := tty .attach (process ); err != nil {
49
70
fatal (err )
50
71
}
72
+ go handleSignals (process , tty )
73
+
51
74
err = container .Restore (process , & libcontainer.CriuOpts {
52
75
ImagesDirectory : imagePath ,
53
76
WorkDirectory : context .String ("work-path" ),
@@ -56,25 +79,42 @@ var restoreCommand = cli.Command{
56
79
ShellJob : context .Bool ("shell-job" ),
57
80
})
58
81
if err != nil {
82
+ tty .Close ()
83
+ if created {
84
+ container .Destroy ()
85
+ }
59
86
fatal (err )
60
87
}
61
- go handleSignals ( process , tty )
88
+
62
89
status , err := process .Wait ()
63
90
if err != nil {
64
91
exitError , ok := err .(* exec.ExitError )
65
92
if ok {
66
93
status = exitError .ProcessState
67
94
} else {
68
- container .Destroy ()
95
+ tty .Close ()
96
+ if created {
97
+ container .Destroy ()
98
+ }
69
99
fatal (err )
70
100
}
71
101
}
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 ()
75
107
fatal (err )
76
108
}
109
+ if status != libcontainer .Checkpointed {
110
+ if err := container .Destroy (); err != nil {
111
+ tty .Close ()
112
+ fatal (err )
113
+ }
114
+ }
77
115
}
116
+
117
+ tty .Close ()
78
118
os .Exit (utils .ExitStatus (status .Sys ().(syscall.WaitStatus )))
79
119
},
80
120
}
0 commit comments