Merge pull request #616 from crosbymichael/runtime-opts
Runtime configs and global reaper
This commit is contained in:
commit
7b06baa1f2
11 changed files with 246 additions and 97 deletions
|
@ -11,11 +11,12 @@ import (
|
|||
"google.golang.org/grpc"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
runc "github.com/crosbymichael/go-runc"
|
||||
"github.com/docker/containerd"
|
||||
shimapi "github.com/docker/containerd/api/services/shim"
|
||||
"github.com/docker/containerd/linux/shim"
|
||||
"github.com/docker/containerd/reaper"
|
||||
"github.com/docker/containerd/sys"
|
||||
"github.com/docker/containerd/utils"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
|
@ -78,6 +79,9 @@ func main() {
|
|||
func setupSignals() (chan os.Signal, error) {
|
||||
signals := make(chan os.Signal, 2048)
|
||||
signal.Notify(signals)
|
||||
// make sure runc is setup to use the monitor
|
||||
// for waiting on processes
|
||||
runc.Monitor = reaper.Default
|
||||
// set the shim as the subreaper for all orphaned processes created by the container
|
||||
if err := sys.SetSubreaper(1); err != nil {
|
||||
return nil, err
|
||||
|
@ -108,7 +112,7 @@ func handleSignals(signals chan os.Signal, server *grpc.Server, service *shim.Se
|
|||
logrus.WithField("signal", s).Debug("received signal")
|
||||
switch s {
|
||||
case syscall.SIGCHLD:
|
||||
exits, err := utils.Reap(false)
|
||||
exits, err := reaper.Reap()
|
||||
if err != nil {
|
||||
logrus.WithError(err).Error("reap exit status")
|
||||
}
|
||||
|
|
|
@ -44,6 +44,8 @@ type config struct {
|
|||
Snapshotter string `toml:"snapshotter"`
|
||||
// Plugins provides plugin specific configuration for the initialization of a plugin
|
||||
Plugins map[string]toml.Primitive `toml:"plugins"`
|
||||
// Enable containerd as a subreaper
|
||||
Subreaper bool `toml:"subreaper"`
|
||||
|
||||
md toml.MetaData
|
||||
}
|
||||
|
@ -58,6 +60,8 @@ func (c *config) decodePlugin(name string, v interface{}) error {
|
|||
|
||||
type grpcConfig struct {
|
||||
Socket string `toml:"socket"`
|
||||
Uid int `toml:"uid"`
|
||||
Gid int `toml:"gid"`
|
||||
}
|
||||
|
||||
type debug struct {
|
||||
|
|
|
@ -21,7 +21,9 @@ import (
|
|||
"github.com/docker/containerd/content"
|
||||
"github.com/docker/containerd/log"
|
||||
"github.com/docker/containerd/plugin"
|
||||
"github.com/docker/containerd/reaper"
|
||||
"github.com/docker/containerd/snapshot"
|
||||
"github.com/docker/containerd/sys"
|
||||
"github.com/docker/containerd/utils"
|
||||
metrics "github.com/docker/go-metrics"
|
||||
"github.com/pkg/errors"
|
||||
|
@ -83,7 +85,13 @@ func main() {
|
|||
// start the signal handler as soon as we can to make sure that
|
||||
// we don't miss any signals during boot
|
||||
signals := make(chan os.Signal, 2048)
|
||||
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1)
|
||||
signal.Notify(signals, syscall.SIGTERM, syscall.SIGINT, syscall.SIGUSR1, syscall.SIGCHLD)
|
||||
if conf.Subreaper {
|
||||
log.G(global).Info("setting subreaper...")
|
||||
if err := sys.SetSubreaper(1); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
log.G(global).Info("starting containerd boot...")
|
||||
|
||||
// load all plugins into containerd
|
||||
|
@ -330,6 +338,9 @@ func serveGRPC(server *grpc.Server) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Chown(path, conf.GRPC.Uid, conf.GRPC.Gid); err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
defer l.Close()
|
||||
if err := server.Serve(l); err != nil {
|
||||
|
@ -360,6 +371,10 @@ func handleSignals(signals chan os.Signal, server *grpc.Server) error {
|
|||
for s := range signals {
|
||||
log.G(global).WithField("signal", s).Debug("received signal")
|
||||
switch s {
|
||||
case syscall.SIGCHLD:
|
||||
if _, err := reaper.Reap(); err != nil {
|
||||
log.G(global).WithError(err).Error("reap containerd processes")
|
||||
}
|
||||
default:
|
||||
server.Stop()
|
||||
return nil
|
||||
|
|
|
@ -193,11 +193,15 @@ var runCommand = cli.Command{
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
abs, err := filepath.Abs(context.String("rootfs"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// for ctr right now just do a bind mount
|
||||
rootfs := []*mount.Mount{
|
||||
{
|
||||
Type: "bind",
|
||||
Source: context.String("rootfs"),
|
||||
Source: abs,
|
||||
Options: []string{
|
||||
"rw",
|
||||
"rbind",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue