Merge pull request #1989 from crosbymichael/reaper
Remove reaper from containerd daemon
This commit is contained in:
commit
90553efdef
@ -12,7 +12,6 @@ func defaultConfig() *server.Config {
|
|||||||
GRPC: server.GRPCConfig{
|
GRPC: server.GRPCConfig{
|
||||||
Address: defaults.DefaultAddress,
|
Address: defaults.DefaultAddress,
|
||||||
},
|
},
|
||||||
NoSubreaper: false,
|
|
||||||
Debug: server.Debug{
|
Debug: server.Debug{
|
||||||
Level: "info",
|
Level: "info",
|
||||||
Address: defaults.DefaultDebugAddress,
|
Address: defaults.DefaultDebugAddress,
|
||||||
|
@ -11,7 +11,6 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
|
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/reaper"
|
|
||||||
"github.com/containerd/containerd/server"
|
"github.com/containerd/containerd/server"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,7 +20,6 @@ var handledSignals = []os.Signal{
|
|||||||
unix.SIGTERM,
|
unix.SIGTERM,
|
||||||
unix.SIGINT,
|
unix.SIGINT,
|
||||||
unix.SIGUSR1,
|
unix.SIGUSR1,
|
||||||
unix.SIGCHLD,
|
|
||||||
unix.SIGPIPE,
|
unix.SIGPIPE,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,10 +34,6 @@ func handleSignals(ctx context.Context, signals chan os.Signal, serverC chan *se
|
|||||||
case s := <-signals:
|
case s := <-signals:
|
||||||
log.G(ctx).WithField("signal", s).Debug("received signal")
|
log.G(ctx).WithField("signal", s).Debug("received signal")
|
||||||
switch s {
|
switch s {
|
||||||
case unix.SIGCHLD:
|
|
||||||
if err := reaper.Reap(); err != nil {
|
|
||||||
log.G(ctx).WithError(err).Error("reap containerd processes")
|
|
||||||
}
|
|
||||||
case unix.SIGUSR1:
|
case unix.SIGUSR1:
|
||||||
dumpStacks()
|
dumpStacks()
|
||||||
case unix.SIGPIPE:
|
case unix.SIGPIPE:
|
||||||
|
@ -26,9 +26,7 @@ import (
|
|||||||
"github.com/containerd/containerd/namespaces"
|
"github.com/containerd/containerd/namespaces"
|
||||||
"github.com/containerd/containerd/platforms"
|
"github.com/containerd/containerd/platforms"
|
||||||
"github.com/containerd/containerd/plugin"
|
"github.com/containerd/containerd/plugin"
|
||||||
"github.com/containerd/containerd/reaper"
|
|
||||||
"github.com/containerd/containerd/runtime"
|
"github.com/containerd/containerd/runtime"
|
||||||
"github.com/containerd/containerd/sys"
|
|
||||||
runc "github.com/containerd/go-runc"
|
runc "github.com/containerd/go-runc"
|
||||||
"github.com/containerd/typeurl"
|
"github.com/containerd/typeurl"
|
||||||
ptypes "github.com/gogo/protobuf/types"
|
ptypes "github.com/gogo/protobuf/types"
|
||||||
@ -159,9 +157,6 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ec := reaper.Default.Subscribe()
|
|
||||||
defer reaper.Default.Unsubscribe(ec)
|
|
||||||
|
|
||||||
bundle, err := newBundle(id,
|
bundle, err := newBundle(id,
|
||||||
filepath.Join(r.state, namespace),
|
filepath.Join(r.state, namespace),
|
||||||
filepath.Join(r.root, namespace),
|
filepath.Join(r.root, namespace),
|
||||||
@ -206,7 +201,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts
|
|||||||
"id": id,
|
"id": id,
|
||||||
"namespace": namespace,
|
"namespace": namespace,
|
||||||
}).Warn("cleaning up after killed shim")
|
}).Warn("cleaning up after killed shim")
|
||||||
err = r.cleanupAfterDeadShim(context.Background(), bundle, namespace, id, lc.pid, ec)
|
err = r.cleanupAfterDeadShim(context.Background(), bundle, namespace, id, lc.pid)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
r.tasks.Delete(ctx, lc)
|
r.tasks.Delete(ctx, lc)
|
||||||
} else {
|
} else {
|
||||||
@ -313,7 +308,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er
|
|||||||
|
|
||||||
rsp, err := lc.shim.Delete(ctx, empty)
|
rsp, err := lc.shim.Delete(ctx, empty)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if cerr := r.cleanupAfterDeadShim(ctx, bundle, namespace, c.ID(), lc.pid, nil); cerr != nil {
|
if cerr := r.cleanupAfterDeadShim(ctx, bundle, namespace, c.ID(), lc.pid); cerr != nil {
|
||||||
log.G(ctx).WithError(err).Error("unable to cleanup task")
|
log.G(ctx).WithError(err).Error("unable to cleanup task")
|
||||||
}
|
}
|
||||||
return nil, errdefs.FromGRPC(err)
|
return nil, errdefs.FromGRPC(err)
|
||||||
@ -394,7 +389,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
|
|||||||
"id": id,
|
"id": id,
|
||||||
"namespace": ns,
|
"namespace": ns,
|
||||||
}).Error("connecting to shim")
|
}).Error("connecting to shim")
|
||||||
err := r.cleanupAfterDeadShim(ctx, bundle, ns, id, pid, nil)
|
err := r.cleanupAfterDeadShim(ctx, bundle, ns, id, pid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.G(ctx).WithError(err).WithField("bundle", bundle.path).
|
log.G(ctx).WithError(err).WithField("bundle", bundle.path).
|
||||||
Error("cleaning up after dead shim")
|
Error("cleaning up after dead shim")
|
||||||
@ -419,7 +414,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
|
|||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns, id string, pid int, ec chan runc.Exit) error {
|
func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns, id string, pid int) error {
|
||||||
ctx = namespaces.WithNamespace(ctx, ns)
|
ctx = namespaces.WithNamespace(ctx, ns)
|
||||||
if err := r.terminate(ctx, bundle, ns, id); err != nil {
|
if err := r.terminate(ctx, bundle, ns, id); err != nil {
|
||||||
if r.config.ShimDebug {
|
if r.config.ShimDebug {
|
||||||
@ -428,17 +423,6 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns,
|
|||||||
log.G(ctx).WithError(err).Warn("failed to terminate task")
|
log.G(ctx).WithError(err).Warn("failed to terminate task")
|
||||||
}
|
}
|
||||||
|
|
||||||
if ec != nil {
|
|
||||||
// if sub-reaper is set, reap our new child
|
|
||||||
if v, err := sys.GetSubreaper(); err == nil && v == 1 {
|
|
||||||
for e := range ec {
|
|
||||||
if e.Pid == pid {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Notify Client
|
// Notify Client
|
||||||
exitedAt := time.Now().UTC()
|
exitedAt := time.Now().UTC()
|
||||||
r.events.Publish(ctx, runtime.TaskExitEventTopic, &eventstypes.TaskExit{
|
r.events.Publish(ctx, runtime.TaskExitEventTopic, &eventstypes.TaskExit{
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"github.com/containerd/containerd/linux/shim"
|
"github.com/containerd/containerd/linux/shim"
|
||||||
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
shimapi "github.com/containerd/containerd/linux/shim/v1"
|
||||||
"github.com/containerd/containerd/log"
|
"github.com/containerd/containerd/log"
|
||||||
"github.com/containerd/containerd/reaper"
|
|
||||||
"github.com/containerd/containerd/sys"
|
"github.com/containerd/containerd/sys"
|
||||||
ptypes "github.com/gogo/protobuf/types"
|
ptypes "github.com/gogo/protobuf/types"
|
||||||
)
|
)
|
||||||
@ -51,8 +50,7 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
ec, err := reaper.Default.Start(cmd)
|
if err := cmd.Start(); err != nil {
|
||||||
if err != nil {
|
|
||||||
return nil, nil, errors.Wrapf(err, "failed to start shim")
|
return nil, nil, errors.Wrapf(err, "failed to start shim")
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -61,7 +59,7 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
reaper.Default.Wait(cmd, ec)
|
cmd.Wait()
|
||||||
exitHandler()
|
exitHandler()
|
||||||
}()
|
}()
|
||||||
log.G(ctx).WithFields(logrus.Fields{
|
log.G(ctx).WithFields(logrus.Fields{
|
||||||
|
@ -23,8 +23,6 @@ type Config struct {
|
|||||||
Metrics MetricsConfig `toml:"metrics"`
|
Metrics MetricsConfig `toml:"metrics"`
|
||||||
// Plugins provides plugin specific configuration for the initialization of a plugin
|
// Plugins provides plugin specific configuration for the initialization of a plugin
|
||||||
Plugins map[string]toml.Primitive `toml:"plugins"`
|
Plugins map[string]toml.Primitive `toml:"plugins"`
|
||||||
// NoSubreaper disables containerd as a subreaper
|
|
||||||
NoSubreaper bool `toml:"no_subreaper"`
|
|
||||||
// OOMScore adjust the containerd's oom score
|
// OOMScore adjust the containerd's oom score
|
||||||
OOMScore int `toml:"oom_score"`
|
OOMScore int `toml:"oom_score"`
|
||||||
// Cgroup specifies cgroup information for the containerd daemon process
|
// Cgroup specifies cgroup information for the containerd daemon process
|
||||||
|
@ -12,12 +12,6 @@ import (
|
|||||||
|
|
||||||
// apply sets config settings on the server process
|
// apply sets config settings on the server process
|
||||||
func apply(ctx context.Context, config *Config) error {
|
func apply(ctx context.Context, config *Config) error {
|
||||||
if !config.NoSubreaper {
|
|
||||||
log.G(ctx).Info("setting subreaper...")
|
|
||||||
if err := sys.SetSubreaper(1); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if config.OOMScore != 0 {
|
if config.OOMScore != 0 {
|
||||||
log.G(ctx).Debugf("changing OOM score to %d", config.OOMScore)
|
log.G(ctx).Debugf("changing OOM score to %d", config.OOMScore)
|
||||||
if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
|
if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user