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"
|
2016-03-12 05:49:45 +08:00
|
|
|
"strings"
|
2015-06-22 10:31:12 +08:00
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/codegangsta/cli"
|
2016-04-13 04:35:51 +08:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2015-06-22 10:31:12 +08:00
|
|
|
)
|
|
|
|
|
2016-03-12 05:49:45 +08:00
|
|
|
// gitCommit will be the hash that the binary was built from
|
|
|
|
// and will be populated by the Makefile
|
|
|
|
var gitCommit = ""
|
|
|
|
|
2015-06-22 10:31:12 +08:00
|
|
|
const (
|
2016-04-26 05:18:35 +08:00
|
|
|
version = "0.1.1"
|
2016-02-06 02:46:12 +08:00
|
|
|
specConfig = "config.json"
|
|
|
|
usage = `Open Container Initiative runtime
|
2016-04-28 22:30:50 +08:00
|
|
|
|
2015-08-08 21:32:30 +08:00
|
|
|
runc is a command line client for running applications packaged according to
|
2016-05-04 07:02:39 +08:00
|
|
|
the Open Container Initiative (OCI) format and is a compliant implementation of the
|
2015-08-08 21:32:30 +08:00
|
|
|
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.
|
2016-04-28 22:30:50 +08:00
|
|
|
The root filesystem contains the contents of the container.
|
2016-02-11 01:30:06 +08:00
|
|
|
|
|
|
|
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
|
2016-03-12 05:49:45 +08:00
|
|
|
v := []string{
|
|
|
|
version,
|
|
|
|
}
|
|
|
|
if gitCommit != "" {
|
|
|
|
v = append(v, fmt.Sprintf("commit: %s", gitCommit))
|
|
|
|
}
|
|
|
|
v = append(v, fmt.Sprintf("spec: %s", specs.Version))
|
|
|
|
app.Version = strings.Join(v, "\n")
|
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",
|
2016-03-09 10:05:50 +08:00
|
|
|
Value: "/dev/null",
|
2015-08-05 03:36:53 +08:00
|
|
|
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",
|
2016-03-11 06:18:39 +08:00
|
|
|
Value: "/run/runc",
|
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",
|
|
|
|
},
|
2016-03-22 03:53:15 +08:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "systemd-cgroup",
|
|
|
|
Usage: "enable systemd cgroup support, expects cgroupsPath to be of form \"slice:prefix:name\" for e.g. \"system.slice:runc:434234\"",
|
|
|
|
},
|
2015-06-22 10:31:12 +08:00
|
|
|
}
|
|
|
|
app.Commands = []cli.Command{
|
|
|
|
checkpointCommand,
|
2016-05-14 07:54:16 +08:00
|
|
|
createCommand,
|
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,
|
2016-03-09 10:05:50 +08:00
|
|
|
initCommand,
|
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-04-22 08:06:35 +08:00
|
|
|
psCommand,
|
2016-01-12 08:57:18 +08:00
|
|
|
restoreCommand,
|
2015-08-15 05:19:10 +08:00
|
|
|
resumeCommand,
|
2016-05-14 06:49:45 +08:00
|
|
|
runCommand,
|
2016-01-12 08:57:18 +08:00
|
|
|
specCommand,
|
2016-05-14 07:54:16 +08:00
|
|
|
startCommand,
|
2016-03-02 00:59:34 +08:00
|
|
|
stateCommand,
|
2016-04-28 22:30:50 +08:00
|
|
|
updateCommand,
|
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 != "" {
|
2016-03-12 09:08:03 +08:00
|
|
|
f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY|os.O_APPEND|os.O_SYNC, 0666)
|
2015-08-05 03:36:53 +08:00
|
|
|
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:
|
2016-05-23 17:32:00 +08:00
|
|
|
return fmt.Errorf("unknown log-format %q", context.GlobalString("log-format"))
|
2015-10-14 07:03:21 +08:00
|
|
|
}
|
2015-06-22 10:31:12 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
2016-03-09 10:05:50 +08:00
|
|
|
fatal(err)
|
2015-06-22 10:31:12 +08:00
|
|
|
}
|
|
|
|
}
|