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
|
|
|
|
2016-06-07 02:45:46 +08:00
|
|
|
"github.com/urfave/cli"
|
2015-06-22 10:31:12 +08:00
|
|
|
)
|
|
|
|
|
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-09-03 01:31:54 +08:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "console-socket",
|
|
|
|
Value: "",
|
|
|
|
Usage: "path to an AF_UNIX socket which will receive a file descriptor referencing the master end of the console's pseudoterminal",
|
|
|
|
},
|
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",
|
|
|
|
},
|
2016-06-04 02:53:07 +08:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "no-new-keyring",
|
|
|
|
Usage: "do not create a new session keyring for the container. This will cause the container to inherit the calling processes session key",
|
|
|
|
},
|
2015-09-02 00:32:29 +08:00
|
|
|
},
|
2016-05-10 13:58:09 +08:00
|
|
|
Action: func(context *cli.Context) error {
|
2016-10-28 23:43:10 +08:00
|
|
|
if err := checkArgs(context, 1, exactArgs); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-11-01 19:13:49 +08:00
|
|
|
if err := revisePidFile(context); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
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
|
|
|
},
|
|
|
|
}
|