2016-05-14 07:54:16 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-05-26 02:24:26 +08:00
|
|
|
"fmt"
|
|
|
|
|
2016-05-18 01:25:28 +08:00
|
|
|
"github.com/opencontainers/runc/libcontainer"
|
2016-06-07 02:45:46 +08:00
|
|
|
"github.com/urfave/cli"
|
2016-05-14 07:54:16 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
var startCommand = cli.Command{
|
|
|
|
Name: "start",
|
2016-05-26 02:24:26 +08:00
|
|
|
Usage: "start signals a created container to execute the user defined process",
|
2016-05-14 07:54:16 +08:00
|
|
|
ArgsUsage: `<container-id>
|
|
|
|
|
|
|
|
Where "<container-id>" is your name for the instance of the container that you
|
|
|
|
are starting. The name you provide for the container instance must be unique on
|
|
|
|
your host.`,
|
|
|
|
Description: `The start command signals the container to start the user's defined process.`,
|
2016-05-26 02:24:26 +08:00
|
|
|
Action: func(context *cli.Context) error {
|
2016-05-14 07:54:16 +08:00
|
|
|
container, err := getContainer(context)
|
|
|
|
if err != nil {
|
2016-05-26 02:24:26 +08:00
|
|
|
return err
|
2016-05-14 07:54:16 +08:00
|
|
|
}
|
2016-05-18 01:25:28 +08:00
|
|
|
status, err := container.Status()
|
|
|
|
if err != nil {
|
2016-05-26 02:24:26 +08:00
|
|
|
return err
|
2016-05-14 07:54:16 +08:00
|
|
|
}
|
2016-05-26 02:24:26 +08:00
|
|
|
switch status {
|
|
|
|
case libcontainer.Created:
|
2016-06-07 04:15:18 +08:00
|
|
|
return container.Exec()
|
2016-05-26 02:24:26 +08:00
|
|
|
case libcontainer.Stopped:
|
|
|
|
return fmt.Errorf("cannot start a container that has run and stopped")
|
|
|
|
case libcontainer.Running:
|
|
|
|
return fmt.Errorf("cannot start an already running container")
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("cannot start a container in the %s state", status)
|
2016-05-18 01:25:28 +08:00
|
|
|
}
|
2016-05-14 07:54:16 +08:00
|
|
|
},
|
|
|
|
}
|