9 "github.com/Sirupsen/logrus"
10 "github.com/opencontainers/runtime-spec/specs-go"
11 "github.com/urfave/cli"
14 // version will be populated by the Makefile, read from
15 // VERSION file of the source code.
18 // gitCommit will be the hash that the binary was built from
19 // and will be populated by the Makefile
23 specConfig = "config.json"
24 usage = `Open Container Initiative runtime
26 runc is a command line client for running applications packaged according to
27 the Open Container Initiative (OCI) format and is a compliant implementation of the
28 Open Container Initiative specification.
30 runc integrates well with existing process supervisors to provide a production
31 container runtime environment for applications. It can be used with your
32 existing process monitoring tools and the container will be spawned as a
33 direct child of the process supervisor.
35 Containers are configured using bundles. A bundle for a container is a directory
36 that includes a specification file named "` + specConfig + `" and a root filesystem.
37 The root filesystem contains the contents of the container.
39 To start a new instance of a container:
41 # runc run [ -b bundle ] <container-id>
43 Where "<container-id>" is your name for the instance of the container that you
44 are starting. The name you provide for the container instance must be unique on
45 your host. Providing the bundle directory using "-b" is optional. The default
46 value for "bundle" is the current directory.`
56 v = append(v, version)
59 v = append(v, fmt.Sprintf("commit: %s", gitCommit))
61 v = append(v, fmt.Sprintf("spec: %s", specs.Version))
62 app.Version = strings.Join(v, "\n")
63 app.Flags = []cli.Flag{
66 Usage: "enable debug output for logging",
71 Usage: "set the log file path where internal debug information is written",
76 Usage: "set the format used by logs ('text' (default), or 'json')",
81 Usage: "root directory for storage of container state (this should be located in tmpfs)",
86 Usage: "path to the criu binary used for checkpoint and restore",
89 Name: "systemd-cgroup",
90 Usage: "enable systemd cgroup support, expects cgroupsPath to be of form \"slice:prefix:name\" for e.g. \"system.slice:runc:434234\"",
93 app.Commands = []cli.Command{
112 app.Before = func(context *cli.Context) error {
113 if context.GlobalBool("debug") {
114 logrus.SetLevel(logrus.DebugLevel)
116 if path := context.GlobalString("log"); path != "" {
117 f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0666)
123 switch context.GlobalString("log-format") {
125 // retain logrus's default.
127 logrus.SetFormatter(new(logrus.JSONFormatter))
129 return fmt.Errorf("unknown log-format %q", context.GlobalString("log-format"))
133 // If the command returns an error, cli takes upon itself to print
134 // the error on cli.ErrWriter and exit.
135 // Use our own writer here to ensure the log gets sent to the right location.
136 cli.ErrWriter = &FatalWriter{cli.ErrWriter}
137 if err := app.Run(os.Args); err != nil {
142 type FatalWriter struct {
143 cliErrWriter io.Writer
146 func (f *FatalWriter) Write(p []byte) (n int, err error) {
147 logrus.Error(string(p))
148 return f.cliErrWriter.Write(p)