@@ -2,6 +2,7 @@ package main
22
33import (
44 "fmt"
5+ "os"
56
67 "github.com/opencontainers/runc/libcontainer"
78 "github.com/urfave/cli"
@@ -10,30 +11,57 @@ import (
1011var startCommand = cli.Command {
1112 Name : "start" ,
1213 Usage : "executes the user defined process in a created container" ,
13- ArgsUsage : `<container-id>
14+ ArgsUsage : `<container-id> [container-id...]
1415
1516Where "<container-id>" is your name for the instance of the container that you
1617are starting. The name you provide for the container instance must be unique on
1718your host.` ,
18- Description : `The start command executes the user defined process in a created container.` ,
19+ Description : `The start command executes the user defined process in a created container .` ,
1920 Action : func (context * cli.Context ) error {
20- container , err := getContainer ( context )
21- if err != nil {
22- return err
21+ hasError := false
22+ if ! context . Args (). Present () {
23+ return fmt . Errorf ( "runc: \" start \" requires a minimum of 1 argument" )
2324 }
24- status , err := container .Status ()
25+
26+ factory , err := loadFactory (context )
2527 if err != nil {
2628 return err
2729 }
28- switch status {
29- case libcontainer .Created :
30- return container .Exec ()
31- case libcontainer .Stopped :
32- return fmt .Errorf ("cannot start a container that has run and stopped" )
33- case libcontainer .Running :
34- return fmt .Errorf ("cannot start an already running container" )
35- default :
36- return fmt .Errorf ("cannot start a container in the %s state" , status )
30+
31+ for _ , id := range context .Args () {
32+ container , err := factory .Load (id )
33+ if err != nil {
34+ fmt .Fprintf (os .Stderr , "container %s is not exist\n " , id )
35+ hasError = true
36+ continue
37+ }
38+ status , err := container .Status ()
39+ if err != nil {
40+ fmt .Fprintf (os .Stderr , "status for %s: %v\n " , id , err )
41+ hasError = true
42+ continue
43+ }
44+ switch status {
45+ case libcontainer .Created :
46+ if err := container .Exec (); err != nil {
47+ fmt .Fprintf (os .Stderr , "start for %s failed: %v\n " , id , err )
48+ hasError = true
49+ }
50+ case libcontainer .Stopped :
51+ fmt .Fprintln (os .Stderr , "cannot start a container that has run and stopped" )
52+ hasError = true
53+ case libcontainer .Running :
54+ fmt .Fprintln (os .Stderr , "cannot start an already running container" )
55+ hasError = true
56+ default :
57+ fmt .Fprintf (os .Stderr , "cannot start a container in the %s state\n " , status )
58+ hasError = true
59+ }
60+ }
61+
62+ if hasError {
63+ return fmt .Errorf ("one or more of container start failed" )
3764 }
65+ return nil
3866 },
3967}
0 commit comments