traefik/vendor/github.com/opencontainers/runc/start.go

44 lines
1.1 KiB
Go
Raw Normal View History

2017-02-07 21:33:23 +00:00
package main
import (
"errors"
2017-02-07 21:33:23 +00:00
"fmt"
"github.com/opencontainers/runc/libcontainer"
"github.com/urfave/cli"
)
var startCommand = cli.Command{
Name: "start",
Usage: "executes the user defined process in a created container",
2017-02-07 21:33:23 +00: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 executes the user defined process in a created container.`,
2017-02-07 21:33:23 +00:00
Action: func(context *cli.Context) error {
if err := checkArgs(context, 1, exactArgs); err != nil {
return err
}
2017-02-07 21:33:23 +00:00
container, err := getContainer(context)
if err != nil {
return err
}
status, err := container.Status()
if err != nil {
return err
}
switch status {
case libcontainer.Created:
return container.Exec()
case libcontainer.Stopped:
return errors.New("cannot start a container that has stopped")
2017-02-07 21:33:23 +00:00
case libcontainer.Running:
return errors.New("cannot start an already running container")
2017-02-07 21:33:23 +00:00
default:
return fmt.Errorf("cannot start a container in the %s state\n", status)
2017-02-07 21:33:23 +00:00
}
},
}