2
2
3
3
package main
4
4
5
- import "github.com/urfave/cli"
5
+ import (
6
+ "fmt"
7
+ "os"
8
+
9
+ "github.com/urfave/cli"
10
+ )
6
11
7
12
var pauseCommand = cli.Command {
8
13
Name : "pause" ,
9
14
Usage : "pause suspends all processes inside the container" ,
10
- ArgsUsage : `<container-id>
15
+ ArgsUsage : `<container-id> [container-id...]
11
16
12
17
Where "<container-id>" is the name for the instance of the container to be
13
18
paused. ` ,
14
19
Description : `The pause command suspends all processes in the instance of the container.
15
20
16
21
Use runc list to identiy instances of containers and their current status.` ,
17
22
Action : func (context * cli.Context ) error {
18
- container , err := getContainer (context )
23
+ hasError := false
24
+ if ! context .Args ().Present () {
25
+ return fmt .Errorf ("runc: \" pause\" requires a minimum of 1 argument" )
26
+ }
27
+
28
+ factory , err := loadFactory (context )
19
29
if err != nil {
20
30
return err
21
31
}
22
- if err := container .Pause (); err != nil {
23
- return err
32
+
33
+ for _ , id := range context .Args () {
34
+ container , err := factory .Load (id )
35
+ if err != nil {
36
+ fmt .Fprintf (os .Stderr , "container %s is not exist\n " , id )
37
+ hasError = true
38
+ continue
39
+ }
40
+ if err := container .Pause (); err != nil {
41
+ fmt .Fprintf (os .Stderr , "pause container %s : %s\n " , id , err )
42
+ hasError = true
43
+ }
44
+ }
45
+
46
+ if hasError {
47
+ return fmt .Errorf ("one or more of container pause failed" )
24
48
}
25
49
return nil
26
50
},
@@ -29,20 +53,39 @@ Use runc list to identiy instances of containers and their current status.`,
29
53
var resumeCommand = cli.Command {
30
54
Name : "resume" ,
31
55
Usage : "resumes all processes that have been previously paused" ,
32
- ArgsUsage : `<container-id>
56
+ ArgsUsage : `<container-id> [container-id...]
33
57
34
58
Where "<container-id>" is the name for the instance of the container to be
35
59
resumed.` ,
36
60
Description : `The resume command resumes all processes in the instance of the container.
37
61
38
62
Use runc list to identiy instances of containers and their current status.` ,
39
63
Action : func (context * cli.Context ) error {
40
- container , err := getContainer (context )
64
+ hasError := false
65
+ if ! context .Args ().Present () {
66
+ return fmt .Errorf ("runc: \" resume\" requires a minimum of 1 argument" )
67
+ }
68
+
69
+ factory , err := loadFactory (context )
41
70
if err != nil {
42
71
return err
43
72
}
44
- if err := container .Resume (); err != nil {
45
- return err
73
+
74
+ for _ , id := range context .Args () {
75
+ container , err := factory .Load (id )
76
+ if err != nil {
77
+ fmt .Fprintf (os .Stderr , "container %s is not exist\n " , id )
78
+ hasError = true
79
+ continue
80
+ }
81
+ if err := container .Resume (); err != nil {
82
+ fmt .Fprintf (os .Stderr , "resume container %s : %s\n " , id , err )
83
+ hasError = true
84
+ }
85
+ }
86
+
87
+ if hasError {
88
+ return fmt .Errorf ("one or more of container resume failed" )
46
89
}
47
90
return nil
48
91
},
0 commit comments