2015-06-22 10:31:12 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-11-18 06:14:02 +08:00
|
|
|
"fmt"
|
2015-06-22 10:31:12 +08:00
|
|
|
"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 (
|
2016-01-26 05:47:54 +08:00
|
|
|
version = "0.0.7"
|
2015-10-28 03:23:44 +08:00
|
|
|
specConfig = "config.json"
|
|
|
|
runtimeConfig = "runtime.json"
|
|
|
|
usage = `Open Container Initiative runtime
|
|
|
|
|
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-10-28 03:23:44 +08:00
|
|
|
After creating config files for your root filesystem with runc, you can execute
|
|
|
|
a 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-10-28 03:23:44 +08:00
|
|
|
# runc start [ -b bundle ]
|
2015-08-18 09:30:17 +08:00
|
|
|
|
2015-10-28 03:23:44 +08:00
|
|
|
If not specified, the default value for the 'bundle' is the current directory.
|
|
|
|
'Bundle' is the directory where '` + specConfig + `' and '` + runtimeConfig + `' must be located.`
|
2015-06-22 10:31:12 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "runc"
|
|
|
|
app.Usage = usage
|
2015-11-18 06:14:02 +08:00
|
|
|
app.Version = fmt.Sprintf("%s\nspec version %s", version, specs.Version)
|
2015-06-22 10:31:12 +08:00
|
|
|
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,
|
2016-01-23 09:29:36 +08:00
|
|
|
listCommand,
|
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)
|
|
|
|
}
|
|
|
|
}
|