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-02-10 03:35:55 +08:00
|
|
|
version = "0.0.8"
|
2016-02-06 02:46:12 +08:00
|
|
|
specConfig = "config.json"
|
|
|
|
usage = `Open Container Initiative runtime
|
2015-10-28 03:23:44 +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
|
|
|
|
2016-02-11 01:30:06 +08:00
|
|
|
Containers are configured using bundles. A bundle for a container is a directory
|
|
|
|
that includes a specification file named "` + specConfig + `" and a root filesystem.
|
|
|
|
The root filesystem contains the contents of the container.
|
|
|
|
|
|
|
|
To start a new instance of a container:
|
2015-06-22 10:31:12 +08:00
|
|
|
|
2016-02-09 06:25:03 +08:00
|
|
|
# runc start [ -b bundle ] <container-id>
|
2015-08-18 09:30:17 +08:00
|
|
|
|
2016-02-11 01:30:06 +08:00
|
|
|
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. Providing the bundle directory using "-b" is optional. The default
|
|
|
|
value for "bundle" is the current directory.`
|
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.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{
|
|
|
|
checkpointCommand,
|
2016-01-12 08:57:18 +08:00
|
|
|
deleteCommand,
|
2015-06-22 10:31:12 +08:00
|
|
|
eventsCommand,
|
2016-01-12 08:57:18 +08:00
|
|
|
execCommand,
|
2015-08-03 18:42:20 +08:00
|
|
|
killCommand,
|
2016-01-12 08:57:18 +08:00
|
|
|
listCommand,
|
2015-08-15 05:19:10 +08:00
|
|
|
pauseCommand,
|
2016-01-12 08:57:18 +08:00
|
|
|
restoreCommand,
|
2015-08-15 05:19:10 +08:00
|
|
|
resumeCommand,
|
2016-01-12 08:57:18 +08:00
|
|
|
specCommand,
|
|
|
|
startCommand,
|
2016-03-02 00:59:34 +08:00
|
|
|
stateCommand,
|
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)
|
|
|
|
}
|
|
|
|
}
|