2015-12-02 22:41:49 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
"github.com/docker/containerd"
|
|
|
|
)
|
|
|
|
|
2016-01-23 22:40:55 +00:00
|
|
|
const usage = `High performance container daemon cli`
|
2015-12-02 22:41:49 +00:00
|
|
|
|
2016-03-22 16:47:35 +00:00
|
|
|
type Exit struct {
|
|
|
|
Code int
|
|
|
|
}
|
|
|
|
|
2015-12-02 22:41:49 +00:00
|
|
|
func main() {
|
2016-03-22 16:47:35 +00:00
|
|
|
// We want our defer functions to be run when calling fatal()
|
|
|
|
defer func() {
|
|
|
|
if e := recover(); e != nil {
|
|
|
|
if ex, ok := e.(Exit); ok == true {
|
|
|
|
os.Exit(ex.Code)
|
|
|
|
}
|
|
|
|
panic(e)
|
|
|
|
}
|
|
|
|
}()
|
2015-12-02 22:41:49 +00:00
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "ctr"
|
2016-03-18 22:29:22 +00:00
|
|
|
if containerd.GitCommit != "" {
|
|
|
|
app.Version = fmt.Sprintf("%s commit: %s", containerd.Version, containerd.GitCommit)
|
|
|
|
} else {
|
|
|
|
app.Version = containerd.Version
|
|
|
|
}
|
2016-01-23 22:40:55 +00:00
|
|
|
app.Usage = usage
|
2015-12-02 22:41:49 +00:00
|
|
|
app.Flags = []cli.Flag{
|
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
Usage: "enable debug output in the logs",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2015-12-14 23:54:11 +00:00
|
|
|
Name: "address",
|
|
|
|
Value: "/run/containerd/containerd.sock",
|
|
|
|
Usage: "address of GRPC API",
|
2015-12-02 22:41:49 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
app.Commands = []cli.Command{
|
2016-01-23 22:40:55 +00:00
|
|
|
checkpointCommand,
|
|
|
|
containersCommand,
|
|
|
|
eventsCommand,
|
2016-02-03 22:30:45 +00:00
|
|
|
stateCommand,
|
2015-12-02 22:41:49 +00:00
|
|
|
}
|
|
|
|
app.Before = func(context *cli.Context) error {
|
|
|
|
if context.GlobalBool("debug") {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
logrus.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func fatal(err string, code int) {
|
2015-12-10 01:03:53 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "[ctr] %s\n", err)
|
2016-03-22 16:47:35 +00:00
|
|
|
panic(Exit{code})
|
2015-12-02 22:41:49 +00:00
|
|
|
}
|