2015-06-22 10:31:12 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/codegangsta/cli"
|
2015-09-02 00:32:29 +08:00
|
|
|
"github.com/opencontainers/specs"
|
2015-06-22 10:31:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2015-09-02 00:32:29 +08:00
|
|
|
version = "0.3"
|
2015-08-08 21:32:30 +08:00
|
|
|
usage = `Open Container Initiative runtime
|
2015-06-26 07:26:31 +08:00
|
|
|
|
2015-08-08 21:32:30 +08:00
|
|
|
runc is a command line client for running applications packaged according to
|
|
|
|
the Open Container Format (OCF) and is a compliant implementation of the
|
|
|
|
Open Container Initiative specification.
|
2015-06-22 10:31:12 +08:00
|
|
|
|
2015-08-08 21:32:30 +08:00
|
|
|
runc integrates well with existing process supervisors to provide a production
|
|
|
|
container runtime environment for applications. It can be used with your
|
|
|
|
existing process monitoring tools and the container will be spawned as a
|
|
|
|
direct child of the process supervisor.
|
2015-06-22 10:31:12 +08:00
|
|
|
|
2015-09-16 09:45:57 +08:00
|
|
|
After creating config files for your root filesystem with runc, you can execute a
|
2015-08-08 21:32:30 +08:00
|
|
|
container in your shell by running:
|
2015-06-22 10:31:12 +08:00
|
|
|
|
2015-09-07 10:39:22 +08:00
|
|
|
# cd /mycontainer
|
2015-09-16 09:45:57 +08:00
|
|
|
# runc start [ -c spec-config-file ] [ -r runtime-config-file ]
|
2015-08-18 09:30:17 +08:00
|
|
|
|
2015-09-16 09:45:57 +08:00
|
|
|
If not specified, the default value for the 'spec-config-file' is 'config.json',
|
|
|
|
and the default value for the 'runtime-config-file' is 'runtime.json'.`
|
2015-06-22 10:31:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "runc"
|
|
|
|
app.Usage = usage
|
|
|
|
app.Version = version
|
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "id",
|
|
|
|
Value: getDefaultID(),
|
|
|
|
Usage: "specify the ID to be used for the container",
|
|
|
|
},
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
Usage: "enable debug output for logging",
|
|
|
|
},
|
2015-08-05 03:36:53 +08:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "log",
|
|
|
|
Usage: "set the log file path where internal debug information is written",
|
|
|
|
},
|
2015-10-14 07:03:21 +08:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "log-format",
|
|
|
|
Value: "text",
|
|
|
|
Usage: "set the format used by logs ('text' (default), or 'json')",
|
|
|
|
},
|
2015-06-22 10:31:12 +08:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "root",
|
2015-09-02 00:32:29 +08:00
|
|
|
Value: specs.LinuxStateDirectory,
|
2015-06-22 10:31:12 +08:00
|
|
|
Usage: "root directory for storage of container state (this should be located in tmpfs)",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "criu",
|
|
|
|
Value: "criu",
|
|
|
|
Usage: "path to the criu binary used for checkpoint and restore",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
app.Commands = []cli.Command{
|
2015-08-18 09:30:17 +08:00
|
|
|
startCommand,
|
2015-06-22 10:31:12 +08:00
|
|
|
checkpointCommand,
|
|
|
|
eventsCommand,
|
|
|
|
restoreCommand,
|
2015-08-03 18:42:20 +08:00
|
|
|
killCommand,
|
2015-06-22 10:31:12 +08:00
|
|
|
specCommand,
|
2015-08-15 05:19:10 +08:00
|
|
|
pauseCommand,
|
|
|
|
resumeCommand,
|
2015-08-15 08:28:28 +08:00
|
|
|
execCommand,
|
2015-06-22 10:31:12 +08:00
|
|
|
}
|
|
|
|
app.Before = func(context *cli.Context) error {
|
|
|
|
if context.GlobalBool("debug") {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
2015-08-05 03:36:53 +08:00
|
|
|
if path := context.GlobalString("log"); path != "" {
|
|
|
|
f, err := os.Create(path)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
logrus.SetOutput(f)
|
|
|
|
}
|
2015-10-14 07:03:21 +08:00
|
|
|
switch context.GlobalString("log-format") {
|
|
|
|
case "text":
|
|
|
|
// retain logrus's default.
|
|
|
|
case "json":
|
|
|
|
logrus.SetFormatter(new(logrus.JSONFormatter))
|
|
|
|
default:
|
|
|
|
logrus.Fatalf("unknown log-format %q", context.GlobalString("log-format"))
|
|
|
|
}
|
2015-06-22 10:31:12 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|