Remove containerd as subreaper
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
85050da1e0
commit
600b4d1154
3 changed files with 38 additions and 35 deletions
|
@ -23,7 +23,6 @@ import (
|
||||||
"github.com/docker/containerd/api/grpc/server"
|
"github.com/docker/containerd/api/grpc/server"
|
||||||
"github.com/docker/containerd/api/grpc/types"
|
"github.com/docker/containerd/api/grpc/types"
|
||||||
"github.com/docker/containerd/api/http/pprof"
|
"github.com/docker/containerd/api/http/pprof"
|
||||||
"github.com/docker/containerd/osutils"
|
|
||||||
"github.com/docker/containerd/supervisor"
|
"github.com/docker/containerd/supervisor"
|
||||||
"github.com/docker/docker/pkg/listeners"
|
"github.com/docker/docker/pkg/listeners"
|
||||||
"github.com/rcrowley/go-metrics"
|
"github.com/rcrowley/go-metrics"
|
||||||
|
@ -160,7 +159,6 @@ func main() {
|
||||||
func daemon(context *cli.Context) error {
|
func daemon(context *cli.Context) error {
|
||||||
s := make(chan os.Signal, 2048)
|
s := make(chan os.Signal, 2048)
|
||||||
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
|
signal.Notify(s, syscall.SIGTERM, syscall.SIGINT)
|
||||||
osutils.SetSubreaper(1)
|
|
||||||
sv, err := supervisor.New(
|
sv, err := supervisor.New(
|
||||||
context.String("state-dir"),
|
context.String("state-dir"),
|
||||||
context.String("runtime"),
|
context.String("runtime"),
|
||||||
|
|
|
@ -14,6 +14,7 @@ import (
|
||||||
"github.com/Sirupsen/logrus"
|
"github.com/Sirupsen/logrus"
|
||||||
"github.com/docker/containerd/specs"
|
"github.com/docker/containerd/specs"
|
||||||
ocs "github.com/opencontainers/runtime-spec/specs-go"
|
ocs "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Container defines the operations allowed on a container
|
// Container defines the operations allowed on a container
|
||||||
|
@ -480,13 +481,34 @@ func (c *container) createCmd(pid string, cmd *exec.Cmd, p *process) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// We need the pid file to have been written to run
|
||||||
|
defer func() {
|
||||||
go func() {
|
go func() {
|
||||||
err := p.cmd.Wait()
|
err := p.cmd.Wait()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
p.cmdSuccess = true
|
p.cmdSuccess = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if same, err := p.isSameProcess(); same && p.pid > 0 {
|
||||||
|
// The process changed its PR_SET_PDEATHSIG, so force
|
||||||
|
// kill it
|
||||||
|
logrus.Infof("containerd: %s:%s (pid %v) has become an orphan, killing it", p.container.id, p.id, p.pid)
|
||||||
|
err = unix.Kill(p.pid, syscall.SIGKILL)
|
||||||
|
if err != nil && err != syscall.ESRCH {
|
||||||
|
logrus.Errorf("containerd: unable to SIGKILL %s:%s (pid %v): %v", p.container.id, p.id, p.pid, err)
|
||||||
|
} else {
|
||||||
|
for {
|
||||||
|
err = unix.Kill(p.pid, 0)
|
||||||
|
if err != nil {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
close(p.cmdDoneCh)
|
close(p.cmdDoneCh)
|
||||||
}()
|
}()
|
||||||
|
}()
|
||||||
if err := c.waitForCreate(p, cmd); err != nil {
|
if err := c.waitForCreate(p, cmd); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,6 +229,9 @@ func (p *process) Resize(w, h int) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *process) updateExitStatusFile(status int) (int, error) {
|
func (p *process) updateExitStatusFile(status int) (int, error) {
|
||||||
|
p.stateLock.Lock()
|
||||||
|
p.state = Stopped
|
||||||
|
p.stateLock.Unlock()
|
||||||
err := ioutil.WriteFile(filepath.Join(p.root, ExitStatusFile), []byte(fmt.Sprintf("%d", status)), 0644)
|
err := ioutil.WriteFile(filepath.Join(p.root, ExitStatusFile), []byte(fmt.Sprintf("%d", status)), 0644)
|
||||||
return status, err
|
return status, err
|
||||||
}
|
}
|
||||||
|
@ -247,9 +250,6 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
|
||||||
// the status to 255
|
// the status to 255
|
||||||
if same, err := p.isSameProcess(); !same {
|
if same, err := p.isSameProcess(); !same {
|
||||||
logrus.Warnf("containerd: %s:%s (pid %d) is not the same process anymore (%v)", p.container.id, p.id, p.pid, err)
|
logrus.Warnf("containerd: %s:%s (pid %d) is not the same process anymore (%v)", p.container.id, p.id, p.pid, err)
|
||||||
p.stateLock.Lock()
|
|
||||||
p.state = Stopped
|
|
||||||
p.stateLock.Unlock()
|
|
||||||
// Create the file so we get the exit event generated once monitor kicks in
|
// Create the file so we get the exit event generated once monitor kicks in
|
||||||
// without having to go through all this process again
|
// without having to go through all this process again
|
||||||
return p.updateExitStatusFile(255)
|
return p.updateExitStatusFile(255)
|
||||||
|
@ -262,13 +262,17 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
|
||||||
if ppid == "1" {
|
if ppid == "1" {
|
||||||
logrus.Warnf("containerd: %s:%s shim died, killing associated process", p.container.id, p.id)
|
logrus.Warnf("containerd: %s:%s shim died, killing associated process", p.container.id, p.id)
|
||||||
unix.Kill(p.pid, syscall.SIGKILL)
|
unix.Kill(p.pid, syscall.SIGKILL)
|
||||||
|
if err != nil && err != syscall.ESRCH {
|
||||||
|
return 255, fmt.Errorf("containerd: unable to SIGKILL %s:%s (pid %v): %v", p.container.id, p.id, p.pid, err)
|
||||||
|
}
|
||||||
|
|
||||||
// wait for the process to die
|
// wait for the process to die
|
||||||
for {
|
for {
|
||||||
e := unix.Kill(p.pid, 0)
|
e := unix.Kill(p.pid, 0)
|
||||||
if e == syscall.ESRCH {
|
if e == syscall.ESRCH {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(10 * time.Millisecond)
|
time.Sleep(5 * time.Millisecond)
|
||||||
}
|
}
|
||||||
// Create the file so we get the exit event generated once monitor kicks in
|
// Create the file so we get the exit event generated once monitor kicks in
|
||||||
// without having to go through all this process again
|
// without having to go through all this process again
|
||||||
|
@ -291,29 +295,8 @@ func (p *process) handleSigkilledShim(rst int, rerr error) (int, error) {
|
||||||
if shimStatus.Signaled() && shimStatus.Signal() == syscall.SIGKILL {
|
if shimStatus.Signaled() && shimStatus.Signal() == syscall.SIGKILL {
|
||||||
logrus.Debugf("containerd: ExitStatus(container: %s, process: %s): shim was SIGKILL'ed reaping its child with pid %d", p.container.id, p.id, p.pid)
|
logrus.Debugf("containerd: ExitStatus(container: %s, process: %s): shim was SIGKILL'ed reaping its child with pid %d", p.container.id, p.id, p.pid)
|
||||||
|
|
||||||
var (
|
|
||||||
status unix.WaitStatus
|
|
||||||
rusage unix.Rusage
|
|
||||||
wpid int
|
|
||||||
)
|
|
||||||
|
|
||||||
// Some processes change their PR_SET_PDEATHSIG, so force kill them
|
|
||||||
unix.Kill(p.pid, syscall.SIGKILL)
|
|
||||||
|
|
||||||
for wpid == 0 {
|
|
||||||
wpid, e = unix.Wait4(p.pid, &status, unix.WNOHANG, &rusage)
|
|
||||||
if e != nil {
|
|
||||||
logrus.Debugf("containerd: ExitStatus(container: %s, process: %s): Wait4(%d): %v", p.container.id, p.id, p.pid, rerr)
|
|
||||||
return rst, rerr
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if wpid == p.pid {
|
|
||||||
rerr = nil
|
rerr = nil
|
||||||
rst = 128 + int(shimStatus.Signal())
|
rst = 128 + int(shimStatus.Signal())
|
||||||
} else {
|
|
||||||
logrus.Errorf("containerd: ExitStatus(container: %s, process: %s): unexpected returned pid from wait4 %v (expected %v)", p.container.id, p.id, wpid, p.pid)
|
|
||||||
}
|
|
||||||
|
|
||||||
p.stateLock.Lock()
|
p.stateLock.Lock()
|
||||||
p.state = Stopped
|
p.state = Stopped
|
||||||
|
|
Loading…
Reference in a new issue