22
33package main
44
5- import "github.com/urfave/cli"
5+ import (
6+ "fmt"
7+ "os"
8+
9+ "github.com/urfave/cli"
10+ )
611
712var pauseCommand = cli.Command {
813 Name : "pause" ,
914 Usage : "pause suspends all processes inside the container" ,
10- ArgsUsage : `<container-id>
15+ ArgsUsage : `<container-id> [container-id...]
1116
1217Where "<container-id>" is the name for the instance of the container to be
1318paused. ` ,
1419 Description : `The pause command suspends all processes in the instance of the container.
1520
1621Use runc list to identiy instances of containers and their current status.` ,
1722 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 )
1929 if err != nil {
2030 return err
2131 }
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" )
2448 }
2549 return nil
2650 },
@@ -29,20 +53,39 @@ Use runc list to identiy instances of containers and their current status.`,
2953var resumeCommand = cli.Command {
3054 Name : "resume" ,
3155 Usage : "resumes all processes that have been previously paused" ,
32- ArgsUsage : `<container-id>
56+ ArgsUsage : `<container-id> [container-id...]
3357
3458Where "<container-id>" is the name for the instance of the container to be
3559resumed.` ,
3660 Description : `The resume command resumes all processes in the instance of the container.
3761
3862Use runc list to identiy instances of containers and their current status.` ,
3963 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 )
4170 if err != nil {
4271 return err
4372 }
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" )
4689 }
4790 return nil
4891 },
0 commit comments