...
1 package main
2
3 import (
4 "errors"
5 "fmt"
6 "os"
7
8 "github.com/opencontainers/runc/libcontainer"
9 "github.com/urfave/cli"
10 )
11
12 var startCommand = cli.Command{
13 Name: "start",
14 Usage: "executes the user defined process in a created container",
15 ArgsUsage: `<container-id>
16
17 Where "<container-id>" is your name for the instance of the container that you
18 are starting. The name you provide for the container instance must be unique on
19 your host.`,
20 Description: `The start command executes the user defined process in a created container.`,
21 Action: func(context *cli.Context) error {
22 if err := checkArgs(context, 1, exactArgs); err != nil {
23 return err
24 }
25 container, err := getContainer(context)
26 if err != nil {
27 return err
28 }
29 status, err := container.Status()
30 if err != nil {
31 return err
32 }
33 switch status {
34 case libcontainer.Created:
35 notifySocket, err := notifySocketStart(context, os.Getenv("NOTIFY_SOCKET"), container.ID())
36 if err != nil {
37 return err
38 }
39 if err := container.Exec(); err != nil {
40 return err
41 }
42 if notifySocket != nil {
43 return notifySocket.waitForContainer(container)
44 }
45 return nil
46 case libcontainer.Stopped:
47 return errors.New("cannot start a container that has stopped")
48 case libcontainer.Running:
49 return errors.New("cannot start an already running container")
50 default:
51 return fmt.Errorf("cannot start a container in the %s state", status)
52 }
53 },
54 }
55
View as plain text