containerd/ctr/main.go
Aleksa Sarai 0ec0bb380f ctr: support proto://address format for --address
In order to match the containerd --listen update, allow users to set any
address of the form proto://address.

Signed-off-by: Aleksa Sarai <asarai@suse.de>
2016-04-23 02:20:46 +10:00

73 lines
1.4 KiB
Go

package main
import (
"fmt"
"os"
"time"
"github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"github.com/docker/containerd"
)
const usage = `High performance container daemon cli`
type Exit struct {
Code int
}
func main() {
// 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)
}
}()
app := cli.NewApp()
app.Name = "ctr"
if containerd.GitCommit != "" {
app.Version = fmt.Sprintf("%s commit: %s", containerd.Version, containerd.GitCommit)
} else {
app.Version = containerd.Version
}
app.Usage = usage
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "debug",
Usage: "enable debug output in the logs",
},
cli.StringFlag{
Name: "address",
Value: "unix:///run/containerd/containerd.sock",
Usage: "proto://address of GRPC API",
},
cli.DurationFlag{
Name: "conn-timeout",
Value: 1 * time.Second,
Usage: "GRPC connection timeout",
},
}
app.Commands = []cli.Command{
checkpointCommand,
containersCommand,
eventsCommand,
stateCommand,
}
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) {
fmt.Fprintf(os.Stderr, "[ctr] %s\n", err)
panic(Exit{code})
}