Move platformInit and plugin load to server
Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
@@ -6,17 +6,13 @@ import (
|
||||
"net"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/boltdb/bolt"
|
||||
gocontext "golang.org/x/net/context"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/containerd/containerd/content"
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/plugin"
|
||||
"github.com/containerd/containerd/server"
|
||||
"github.com/containerd/containerd/sys"
|
||||
"github.com/containerd/containerd/version"
|
||||
@@ -89,18 +85,9 @@ func main() {
|
||||
if address == "" {
|
||||
return errors.New("grpc address cannot be empty")
|
||||
}
|
||||
|
||||
if err := platformInit(ctx, config); err != nil {
|
||||
return err
|
||||
}
|
||||
log.G(ctx).Info("starting containerd boot...")
|
||||
|
||||
plugins, err := loadPlugins(config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
server, err := server.New(ctx, config, plugins)
|
||||
server, err := server.New(ctx, config)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -186,41 +173,6 @@ func setLevel(context *cli.Context, config *server.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func loadPlugins(config *server.Config) ([]*plugin.Registration, error) {
|
||||
// load all plugins into containerd
|
||||
if err := plugin.Load(filepath.Join(config.Root, "plugins")); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// load additional plugins that don't automatically register themselves
|
||||
registerContentStore()
|
||||
registerMetaDB()
|
||||
// return the ordered graph for plugins
|
||||
return plugin.Graph(), nil
|
||||
}
|
||||
|
||||
func registerContentStore() {
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.ContentPlugin,
|
||||
ID: "content",
|
||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
return content.NewStore(ic.Root)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func registerMetaDB() {
|
||||
plugin.Register(&plugin.Registration{
|
||||
Type: plugin.MetadataPlugin,
|
||||
ID: "bolt",
|
||||
Init: func(ic *plugin.InitContext) (interface{}, error) {
|
||||
if err := os.MkdirAll(ic.Root, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return bolt.Open(filepath.Join(ic.Root, "meta.db"), 0644, nil)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func dumpStacks() {
|
||||
var (
|
||||
buf []byte
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
"github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/reaper"
|
||||
"github.com/containerd/containerd/server"
|
||||
"github.com/containerd/containerd/sys"
|
||||
)
|
||||
|
||||
const defaultConfigPath = "/etc/containerd/config.toml"
|
||||
@@ -21,22 +20,6 @@ var handledSignals = []os.Signal{
|
||||
unix.SIGCHLD,
|
||||
}
|
||||
|
||||
func platformInit(ctx context.Context, config *server.Config) error {
|
||||
if config.Subreaper {
|
||||
log.G(ctx).Info("setting subreaper...")
|
||||
if err := sys.SetSubreaper(1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if config.OOMScore != 0 {
|
||||
log.G(ctx).Infof("changing OOM score to %d", config.OOMScore)
|
||||
if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSignals(ctx context.Context, signals chan os.Signal, server *server.Server) error {
|
||||
for s := range signals {
|
||||
log.G(ctx).WithField("signal", s).Debug("received signal")
|
||||
|
||||
@@ -22,10 +22,6 @@ var handledSignals = []os.Signal{
|
||||
unix.SIGCHLD,
|
||||
}
|
||||
|
||||
func platformInit(context context.Context, config *server.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSignals(ctx context.Context, signals chan os.Signal, server *server.Server) error {
|
||||
for s := range signals {
|
||||
log.G(ctx).WithField("signal", s).Debug("received signal")
|
||||
|
||||
@@ -18,10 +18,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func platformInit(context context.Context, config *server.Config) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleSignals(ctx context.Context, signals chan os.Signal, server *server.Server) error {
|
||||
for s := range signals {
|
||||
log.G(ctx).WithField("signal", s).Debug("received signal")
|
||||
|
||||
Reference in New Issue
Block a user