2016-11-30 00:10:41 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-01-30 06:00:57 +00:00
|
|
|
_ "expvar"
|
2016-11-30 00:10:41 +00:00
|
|
|
"fmt"
|
2017-04-04 19:57:35 +00:00
|
|
|
"io/ioutil"
|
2016-12-11 19:07:32 +00:00
|
|
|
"net/http"
|
2017-01-30 06:00:57 +00:00
|
|
|
_ "net/http/pprof"
|
2016-11-30 00:10:41 +00:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
2017-02-18 00:49:59 +00:00
|
|
|
"path/filepath"
|
2017-02-13 18:23:28 +00:00
|
|
|
"time"
|
2016-11-30 00:10:41 +00:00
|
|
|
|
2017-04-04 01:40:59 +00:00
|
|
|
"github.com/boltdb/bolt"
|
2017-03-14 23:16:49 +00:00
|
|
|
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
|
2016-12-12 22:26:51 +00:00
|
|
|
gocontext "golang.org/x/net/context"
|
2016-11-30 00:10:41 +00:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
|
2017-01-19 06:14:37 +00:00
|
|
|
"github.com/Sirupsen/logrus"
|
2017-04-03 20:14:15 +00:00
|
|
|
"github.com/containerd/containerd"
|
|
|
|
contentapi "github.com/containerd/containerd/api/services/content"
|
|
|
|
api "github.com/containerd/containerd/api/services/execution"
|
2017-04-04 01:40:59 +00:00
|
|
|
imagesapi "github.com/containerd/containerd/api/services/images"
|
2017-04-03 20:14:15 +00:00
|
|
|
rootfsapi "github.com/containerd/containerd/api/services/rootfs"
|
|
|
|
"github.com/containerd/containerd/content"
|
2017-04-04 01:40:59 +00:00
|
|
|
"github.com/containerd/containerd/images"
|
2017-04-03 20:14:15 +00:00
|
|
|
"github.com/containerd/containerd/log"
|
|
|
|
"github.com/containerd/containerd/plugin"
|
|
|
|
"github.com/containerd/containerd/snapshot"
|
|
|
|
"github.com/containerd/containerd/sys"
|
2016-12-11 19:07:32 +00:00
|
|
|
metrics "github.com/docker/go-metrics"
|
2017-02-06 22:57:43 +00:00
|
|
|
"github.com/pkg/errors"
|
2016-11-30 00:10:41 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2017-01-19 22:16:50 +00:00
|
|
|
const usage = `
|
2016-11-30 00:10:41 +00:00
|
|
|
__ _ __
|
|
|
|
_________ ____ / /_____ _(_)___ ___ _________/ /
|
2016-12-05 22:15:03 +00:00
|
|
|
/ ___/ __ \/ __ \/ __/ __ ` + "`" + `/ / __ \/ _ \/ ___/ __ /
|
|
|
|
/ /__/ /_/ / / / / /_/ /_/ / / / / / __/ / / /_/ /
|
|
|
|
\___/\____/_/ /_/\__/\__,_/_/_/ /_/\___/_/ \__,_/
|
|
|
|
|
2016-11-30 00:10:41 +00:00
|
|
|
high performance container runtime
|
|
|
|
`
|
2017-01-19 22:16:50 +00:00
|
|
|
|
2017-02-21 19:07:54 +00:00
|
|
|
var (
|
|
|
|
conf = defaultConfig()
|
|
|
|
global = log.WithModule(gocontext.Background(), "containerd")
|
|
|
|
)
|
2017-02-06 22:57:43 +00:00
|
|
|
|
2017-02-22 21:16:06 +00:00
|
|
|
func init() {
|
|
|
|
cli.VersionPrinter = func(c *cli.Context) {
|
|
|
|
fmt.Println(c.App.Name, containerd.Package, c.App.Version)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-19 22:16:50 +00:00
|
|
|
func main() {
|
|
|
|
app := cli.NewApp()
|
|
|
|
app.Name = "containerd"
|
|
|
|
app.Version = containerd.Version
|
|
|
|
app.Usage = usage
|
2016-11-30 00:10:41 +00:00
|
|
|
app.Flags = []cli.Flag{
|
2017-01-24 10:16:16 +00:00
|
|
|
cli.StringFlag{
|
2017-02-21 19:07:54 +00:00
|
|
|
Name: "config,c",
|
2017-04-04 19:57:35 +00:00
|
|
|
Usage: "path to the configuration file (Use 'default' to output the default toml)",
|
2017-03-17 23:09:06 +00:00
|
|
|
Value: defaultConfigPath,
|
2017-01-24 10:16:16 +00:00
|
|
|
},
|
2016-12-02 19:33:58 +00:00
|
|
|
cli.StringFlag{
|
2017-02-21 19:07:54 +00:00
|
|
|
Name: "log-level,l",
|
|
|
|
Usage: "set the logging level [debug, info, warn, error, fatal, panic]",
|
2016-12-02 19:33:58 +00:00
|
|
|
},
|
2017-01-30 06:00:57 +00:00
|
|
|
cli.StringFlag{
|
2017-02-21 19:07:54 +00:00
|
|
|
Name: "state",
|
|
|
|
Usage: "containerd state directory",
|
2017-01-30 06:00:57 +00:00
|
|
|
},
|
2016-12-01 18:34:42 +00:00
|
|
|
cli.StringFlag{
|
2017-03-17 23:09:06 +00:00
|
|
|
Name: "address,a",
|
|
|
|
Usage: "address for containerd's GRPC server",
|
2016-12-01 18:34:42 +00:00
|
|
|
},
|
2017-02-16 22:45:13 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "root",
|
|
|
|
Usage: "containerd root directory",
|
|
|
|
},
|
2016-11-30 00:10:41 +00:00
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
app.Before = before
|
2016-11-30 00:10:41 +00:00
|
|
|
app.Action = func(context *cli.Context) error {
|
2017-02-13 18:23:28 +00:00
|
|
|
start := time.Now()
|
|
|
|
// start the signal handler as soon as we can to make sure that
|
|
|
|
// we don't miss any signals during boot
|
2016-11-30 00:10:41 +00:00
|
|
|
signals := make(chan os.Signal, 2048)
|
2017-03-17 23:09:06 +00:00
|
|
|
signal.Notify(signals, handledSignals...)
|
|
|
|
if err := platformInit(context); err != nil {
|
|
|
|
return err
|
2017-03-10 00:26:14 +00:00
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
log.G(global).Info("starting containerd boot...")
|
2017-02-16 22:45:13 +00:00
|
|
|
|
|
|
|
// load all plugins into containerd
|
2017-03-07 01:23:00 +00:00
|
|
|
if err := plugin.Load(filepath.Join(conf.Root, "plugins")); err != nil {
|
2017-02-16 22:45:13 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
// start debug and metrics APIs
|
|
|
|
if err := serveDebugAPI(); err != nil {
|
2017-01-30 06:00:57 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-03-21 18:39:44 +00:00
|
|
|
monitor, err := loadMonitor()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
runtimes, err := loadRuntimes(monitor)
|
2016-11-30 00:10:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-16 22:45:13 +00:00
|
|
|
store, err := resolveContentStore()
|
|
|
|
if err != nil {
|
2017-01-12 18:32:09 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-04-04 01:40:59 +00:00
|
|
|
meta, err := resolveMetaDB(context)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer meta.Close()
|
2017-03-07 22:55:36 +00:00
|
|
|
snapshotter, err := loadSnapshotter(store)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-04-04 01:40:59 +00:00
|
|
|
services, err := loadServices(runtimes, store, snapshotter, meta)
|
2017-02-18 00:49:59 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
// start the GRPC api with the execution service registered
|
2017-02-18 00:49:59 +00:00
|
|
|
server := newGRPCServer()
|
2017-02-16 22:45:13 +00:00
|
|
|
for _, service := range services {
|
|
|
|
if err := service.Register(server); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2017-03-14 07:39:29 +00:00
|
|
|
log.G(global).Info("starting GRPC API server...")
|
2017-02-21 19:07:54 +00:00
|
|
|
if err := serveGRPC(server); err != nil {
|
2016-12-02 19:33:58 +00:00
|
|
|
return err
|
|
|
|
}
|
2017-02-16 22:45:13 +00:00
|
|
|
// start the prometheus metrics API for containerd
|
|
|
|
serveMetricsAPI()
|
|
|
|
|
2017-03-30 08:41:22 +00:00
|
|
|
log.G(global).Infof("containerd successfully booted in %fs", time.Since(start).Seconds())
|
2017-02-13 18:23:28 +00:00
|
|
|
return handleSignals(signals, server)
|
2016-11-30 00:10:41 +00:00
|
|
|
}
|
2017-02-18 00:49:59 +00:00
|
|
|
|
2016-11-30 00:10:41 +00:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
|
|
fmt.Fprintf(os.Stderr, "containerd: %s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-13 18:23:28 +00:00
|
|
|
func before(context *cli.Context) error {
|
2017-04-04 19:57:35 +00:00
|
|
|
if context.GlobalString("config") == "default" {
|
|
|
|
fh, err := ioutil.TempFile("", "containerd-config.toml.")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := conf.WriteTo(fh); err != nil {
|
|
|
|
fh.Close()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fh.Close()
|
|
|
|
log.G(global).Infof("containerd default config written to %q", fh.Name())
|
|
|
|
os.Exit(0)
|
|
|
|
}
|
2017-04-04 19:31:35 +00:00
|
|
|
err := loadConfig(context.GlobalString("config"))
|
|
|
|
if err != nil && !os.IsNotExist(err) {
|
2017-02-21 19:07:54 +00:00
|
|
|
return err
|
2017-04-04 19:31:35 +00:00
|
|
|
} else if err != nil && os.IsNotExist(err) {
|
|
|
|
log.G(global).Infof("config %q does not exist. Creating it.", context.GlobalString("config"))
|
|
|
|
fh, err := os.Create(context.GlobalString("config"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if _, err := conf.WriteTo(fh); err != nil {
|
|
|
|
fh.Close()
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fh.Close()
|
2017-02-21 19:07:54 +00:00
|
|
|
}
|
2017-04-04 19:31:35 +00:00
|
|
|
|
2017-02-21 19:07:54 +00:00
|
|
|
// the order for config vs flag values is that flags will always override
|
|
|
|
// the config values if they are set
|
|
|
|
if err := setLevel(context); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
for _, v := range []struct {
|
|
|
|
name string
|
|
|
|
d *string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "root",
|
|
|
|
d: &conf.Root,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "state",
|
|
|
|
d: &conf.State,
|
|
|
|
},
|
|
|
|
{
|
2017-03-17 23:09:06 +00:00
|
|
|
name: "address",
|
|
|
|
d: &conf.GRPC.Address,
|
2017-02-21 19:07:54 +00:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
if s := context.GlobalString(v.name); s != "" {
|
|
|
|
*v.d = s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func setLevel(context *cli.Context) error {
|
|
|
|
l := context.GlobalString("log-level")
|
|
|
|
if l == "" {
|
|
|
|
l = conf.Debug.Level
|
|
|
|
}
|
|
|
|
if l != "" {
|
2017-02-13 18:23:28 +00:00
|
|
|
lvl, err := logrus.ParseLevel(l)
|
|
|
|
if err != nil {
|
2017-02-21 19:07:54 +00:00
|
|
|
return err
|
2017-02-13 18:23:28 +00:00
|
|
|
}
|
|
|
|
logrus.SetLevel(lvl)
|
|
|
|
}
|
|
|
|
return nil
|
2016-12-11 19:07:32 +00:00
|
|
|
}
|
2016-12-01 18:34:42 +00:00
|
|
|
|
2017-02-21 19:07:54 +00:00
|
|
|
func serveMetricsAPI() {
|
|
|
|
if conf.Metrics.Address != "" {
|
|
|
|
log.G(global).WithField("metrics", conf.Metrics.Address).Info("starting metrics API...")
|
2017-02-13 18:23:28 +00:00
|
|
|
h := newMetricsHandler()
|
|
|
|
go func() {
|
2017-02-21 19:07:54 +00:00
|
|
|
if err := http.ListenAndServe(conf.Metrics.Address, h); err != nil {
|
2017-02-13 18:23:28 +00:00
|
|
|
log.G(global).WithError(err).Fatal("serve metrics API")
|
|
|
|
}
|
|
|
|
}()
|
2016-11-30 00:10:41 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-11 19:07:32 +00:00
|
|
|
|
2017-02-13 18:23:28 +00:00
|
|
|
func newMetricsHandler() http.Handler {
|
|
|
|
m := http.NewServeMux()
|
|
|
|
m.Handle("/metrics", metrics.Handler())
|
|
|
|
return m
|
2017-01-30 06:00:57 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 19:07:54 +00:00
|
|
|
func serveDebugAPI() error {
|
2017-03-17 23:09:06 +00:00
|
|
|
path := conf.Debug.Address
|
2017-02-13 18:23:28 +00:00
|
|
|
if path == "" {
|
2017-02-21 19:07:54 +00:00
|
|
|
return errors.New("debug socket path cannot be empty")
|
2017-02-13 18:23:28 +00:00
|
|
|
}
|
2017-03-17 23:09:06 +00:00
|
|
|
l, err := sys.GetLocalListener(path, conf.GRPC.Uid, conf.GRPC.Gid)
|
2017-02-13 18:23:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-12-11 19:07:32 +00:00
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
log.G(global).WithField("debug", path).Info("starting debug API...")
|
|
|
|
go func() {
|
|
|
|
defer l.Close()
|
|
|
|
// pprof and expvars are imported and automatically register their endpoints
|
|
|
|
// under /debug
|
|
|
|
if err := http.Serve(l, nil); err != nil {
|
|
|
|
log.G(global).WithError(err).Fatal("serve debug API")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return nil
|
2016-12-11 19:07:32 +00:00
|
|
|
}
|
2016-12-12 22:26:51 +00:00
|
|
|
|
2017-02-21 23:27:12 +00:00
|
|
|
func resolveContentStore() (*content.Store, error) {
|
2017-02-18 00:49:59 +00:00
|
|
|
cp := filepath.Join(conf.Root, "content")
|
|
|
|
return content.NewStore(cp)
|
|
|
|
}
|
|
|
|
|
2017-04-04 01:40:59 +00:00
|
|
|
func resolveMetaDB(ctx *cli.Context) (*bolt.DB, error) {
|
|
|
|
path := filepath.Join(conf.Root, "meta.db")
|
|
|
|
|
|
|
|
db, err := bolt.Open(path, 0644, nil)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO(stevvooe): Break these down into components to be initialized.
|
|
|
|
if err := images.InitDB(db); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return db, nil
|
|
|
|
}
|
|
|
|
|
2017-03-21 18:39:44 +00:00
|
|
|
func loadRuntimes(monitor plugin.ContainerMonitor) (map[string]containerd.Runtime, error) {
|
2017-02-16 22:45:13 +00:00
|
|
|
o := make(map[string]containerd.Runtime)
|
2017-03-07 01:23:00 +00:00
|
|
|
for name, rr := range plugin.Registrations() {
|
|
|
|
if rr.Type != plugin.RuntimePlugin {
|
2017-02-16 22:45:13 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.G(global).Infof("loading runtime plugin %q...", name)
|
2017-03-07 01:23:00 +00:00
|
|
|
ic := &plugin.InitContext{
|
2017-02-16 22:45:13 +00:00
|
|
|
Root: conf.Root,
|
|
|
|
State: conf.State,
|
|
|
|
Context: log.WithModule(global, fmt.Sprintf("runtime-%s", name)),
|
2017-03-21 18:39:44 +00:00
|
|
|
Monitor: monitor,
|
2017-02-16 22:45:13 +00:00
|
|
|
}
|
|
|
|
if rr.Config != nil {
|
|
|
|
if err := conf.decodePlugin(name, rr.Config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ic.Config = rr.Config
|
|
|
|
}
|
|
|
|
vr, err := rr.Init(ic)
|
2017-02-13 18:23:28 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2016-12-12 22:26:51 +00:00
|
|
|
}
|
2017-02-16 22:45:13 +00:00
|
|
|
o[name] = vr.(containerd.Runtime)
|
2017-02-06 22:57:43 +00:00
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
return o, nil
|
|
|
|
}
|
2016-12-12 22:26:51 +00:00
|
|
|
|
2017-03-21 18:39:44 +00:00
|
|
|
func loadMonitor() (plugin.ContainerMonitor, error) {
|
|
|
|
var monitors []plugin.ContainerMonitor
|
|
|
|
for name, m := range plugin.Registrations() {
|
|
|
|
if m.Type != plugin.ContainerMonitorPlugin {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.G(global).Infof("loading monitor plugin %q...", name)
|
|
|
|
ic := &plugin.InitContext{
|
|
|
|
Root: conf.Root,
|
|
|
|
State: conf.State,
|
|
|
|
Context: log.WithModule(global, fmt.Sprintf("monitor-%s", name)),
|
|
|
|
}
|
|
|
|
mm, err := m.Init(ic)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
monitors = append(monitors, mm.(plugin.ContainerMonitor))
|
|
|
|
}
|
|
|
|
if len(monitors) == 0 {
|
|
|
|
return plugin.NewNoopMonitor(), nil
|
|
|
|
}
|
|
|
|
return plugin.NewMultiContainerMonitor(monitors...), nil
|
|
|
|
}
|
|
|
|
|
2017-03-07 22:55:36 +00:00
|
|
|
func loadSnapshotter(store *content.Store) (snapshot.Snapshotter, error) {
|
|
|
|
for name, sr := range plugin.Registrations() {
|
|
|
|
if sr.Type != plugin.SnapshotPlugin {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
moduleName := fmt.Sprintf("snapshot-%s", conf.Snapshotter)
|
|
|
|
if name != moduleName {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
log.G(global).Infof("loading snapshot plugin %q...", name)
|
|
|
|
ic := &plugin.InitContext{
|
|
|
|
Root: conf.Root,
|
|
|
|
State: conf.State,
|
2017-04-04 01:40:59 +00:00
|
|
|
Content: store,
|
2017-03-07 22:55:36 +00:00
|
|
|
Context: log.WithModule(global, moduleName),
|
|
|
|
}
|
|
|
|
if sr.Config != nil {
|
|
|
|
if err := conf.decodePlugin(name, sr.Config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ic.Config = sr.Config
|
|
|
|
}
|
|
|
|
sn, err := sr.Init(ic)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return sn.(snapshot.Snapshotter), nil
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("snapshotter not loaded: %v", conf.Snapshotter)
|
|
|
|
}
|
|
|
|
|
2017-02-18 00:49:59 +00:00
|
|
|
func newGRPCServer() *grpc.Server {
|
2017-03-14 23:16:49 +00:00
|
|
|
s := grpc.NewServer(
|
|
|
|
grpc.UnaryInterceptor(interceptor),
|
|
|
|
grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor),
|
|
|
|
)
|
2017-02-13 18:23:28 +00:00
|
|
|
return s
|
2016-12-12 22:26:51 +00:00
|
|
|
}
|
|
|
|
|
2017-04-04 01:40:59 +00:00
|
|
|
func loadServices(runtimes map[string]containerd.Runtime, store *content.Store, sn snapshot.Snapshotter, meta *bolt.DB) ([]plugin.Service, error) {
|
2017-03-07 01:23:00 +00:00
|
|
|
var o []plugin.Service
|
|
|
|
for name, sr := range plugin.Registrations() {
|
|
|
|
if sr.Type != plugin.GRPCPlugin {
|
2017-02-16 22:45:13 +00:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
log.G(global).Infof("loading grpc service plugin %q...", name)
|
2017-03-07 01:23:00 +00:00
|
|
|
ic := &plugin.InitContext{
|
2017-03-07 22:55:36 +00:00
|
|
|
Root: conf.Root,
|
|
|
|
State: conf.State,
|
|
|
|
Context: log.WithModule(global, fmt.Sprintf("service-%s", name)),
|
|
|
|
Runtimes: runtimes,
|
2017-04-04 01:40:59 +00:00
|
|
|
Content: store,
|
|
|
|
Meta: meta,
|
2017-03-07 22:55:36 +00:00
|
|
|
Snapshotter: sn,
|
2017-02-16 22:45:13 +00:00
|
|
|
}
|
|
|
|
if sr.Config != nil {
|
|
|
|
if err := conf.decodePlugin(name, sr.Config); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
ic.Config = sr.Config
|
|
|
|
}
|
|
|
|
vs, err := sr.Init(ic)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-03-07 01:23:00 +00:00
|
|
|
o = append(o, vs.(plugin.Service))
|
2017-02-16 22:45:13 +00:00
|
|
|
}
|
|
|
|
return o, nil
|
|
|
|
}
|
|
|
|
|
2017-02-21 19:07:54 +00:00
|
|
|
func serveGRPC(server *grpc.Server) error {
|
2017-03-17 23:09:06 +00:00
|
|
|
path := conf.GRPC.Address
|
2017-02-13 18:23:28 +00:00
|
|
|
if path == "" {
|
|
|
|
return errors.New("--socket path cannot be empty")
|
|
|
|
}
|
2017-03-17 23:09:06 +00:00
|
|
|
l, err := sys.GetLocalListener(path, conf.GRPC.Uid, conf.GRPC.Gid)
|
2016-12-12 22:26:51 +00:00
|
|
|
if err != nil {
|
2017-02-13 18:23:28 +00:00
|
|
|
return err
|
2016-12-12 22:26:51 +00:00
|
|
|
}
|
2017-02-13 18:23:28 +00:00
|
|
|
go func() {
|
|
|
|
defer l.Close()
|
|
|
|
if err := server.Serve(l); err != nil {
|
|
|
|
log.G(global).WithError(err).Fatal("serve GRPC")
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|
2017-02-06 22:57:43 +00:00
|
|
|
|
2017-02-13 18:23:28 +00:00
|
|
|
func interceptor(ctx gocontext.Context,
|
|
|
|
req interface{},
|
|
|
|
info *grpc.UnaryServerInfo,
|
|
|
|
handler grpc.UnaryHandler,
|
|
|
|
) (interface{}, error) {
|
|
|
|
ctx = log.WithModule(ctx, "containerd")
|
|
|
|
switch info.Server.(type) {
|
|
|
|
case api.ContainerServiceServer:
|
2017-03-01 00:47:10 +00:00
|
|
|
ctx = log.WithModule(ctx, "execution")
|
|
|
|
case contentapi.ContentServer:
|
|
|
|
ctx = log.WithModule(ctx, "content")
|
2017-03-09 06:04:44 +00:00
|
|
|
case rootfsapi.RootFSServer:
|
|
|
|
ctx = log.WithModule(ctx, "rootfs")
|
2017-04-04 01:40:59 +00:00
|
|
|
case imagesapi.ImagesServer:
|
|
|
|
ctx = log.WithModule(ctx, "images")
|
2017-02-13 18:23:28 +00:00
|
|
|
default:
|
|
|
|
fmt.Printf("unknown GRPC server type: %#v\n", info.Server)
|
2016-12-12 22:26:51 +00:00
|
|
|
}
|
2017-03-14 23:16:49 +00:00
|
|
|
return grpc_prometheus.UnaryServerInterceptor(ctx, req, info, handler)
|
2017-02-13 18:23:28 +00:00
|
|
|
}
|