2015-06-30 07:49:13 +08:00
|
|
|
// +build linux
|
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-06-25 15:19:44 +08:00
|
|
|
"os"
|
2015-06-22 10:31:12 +08:00
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
)
|
|
|
|
|
2015-08-29 23:50:39 +08:00
|
|
|
// default action is to start a container
|
2016-05-14 06:49:45 +08:00
|
|
|
var runCommand = cli.Command{
|
|
|
|
Name: "run",
|
2015-08-18 09:30:17 +08:00
|
|
|
Usage: "create and run a container",
|
2016-02-11 01:30:06 +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.`,
|
2016-05-14 06:49:45 +08:00
|
|
|
Description: `The run command creates an instance of a container for a bundle. The bundle
|
2016-03-19 02:54:06 +08:00
|
|
|
is a directory with a specification file named "` + specConfig + `" and a root
|
|
|
|
filesystem.
|
|
|
|
|
|
|
|
The specification file includes an args parameter. The args parameter is used
|
|
|
|
to specify command(s) that get run when the container is started. To change the
|
|
|
|
command(s) that get executed on start, edit the args parameter of the spec. See
|
|
|
|
"runc spec --help" for more explanation.`,
|
2015-09-02 00:32:29 +08:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
2015-10-28 03:23:44 +08:00
|
|
|
Name: "bundle, b",
|
|
|
|
Value: "",
|
2016-02-11 01:30:06 +08:00
|
|
|
Usage: `path to the root of the bundle directory, defaults to the current directory`,
|
2015-09-02 00:32:29 +08:00
|
|
|
},
|
2016-01-08 06:34:11 +08:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "console",
|
|
|
|
Value: "",
|
|
|
|
Usage: "specify the pty slave path for use with the container",
|
|
|
|
},
|
2016-01-12 08:57:18 +08:00
|
|
|
cli.BoolFlag{
|
2016-05-20 08:28:58 +08:00
|
|
|
Name: "detach, d",
|
2016-01-12 08:57:18 +08:00
|
|
|
Usage: "detach from the container's process",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "pid-file",
|
|
|
|
Value: "",
|
|
|
|
Usage: "specify the file to write the process id to",
|
|
|
|
},
|
2016-03-15 06:46:08 +08:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "no-subreaper",
|
|
|
|
Usage: "disable the use of the subreaper used to reap reparented processes",
|
|
|
|
},
|
2016-03-31 02:12:03 +08:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "no-pivot",
|
|
|
|
Usage: "do not use pivot root to jail process inside rootfs. This should be used whenever the rootfs is on top of a ramdisk",
|
|
|
|
},
|
2015-09-02 00:32:29 +08:00
|
|
|
},
|
2016-05-10 13:58:09 +08:00
|
|
|
Action: func(context *cli.Context) error {
|
2016-05-26 02:24:26 +08:00
|
|
|
spec, err := setupSpec(context)
|
2015-08-27 23:03:43 +08:00
|
|
|
if err != nil {
|
2016-05-10 13:58:09 +08:00
|
|
|
return err
|
2015-08-27 23:03:43 +08:00
|
|
|
}
|
2016-05-14 07:54:16 +08:00
|
|
|
status, err := startContainer(context, spec, false)
|
2016-05-10 13:58:09 +08:00
|
|
|
if err == nil {
|
|
|
|
// exit with the container's exit status so any external supervisor is
|
|
|
|
// notified of the exit with the correct exit status.
|
|
|
|
os.Exit(status)
|
2015-08-18 09:30:17 +08:00
|
|
|
}
|
2016-05-10 13:58:09 +08:00
|
|
|
return err
|
2015-08-18 09:30:17 +08:00
|
|
|
},
|
|
|
|
}
|