2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2015-12-19 00:54:02 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
2016-01-06 21:32:46 +00:00
|
|
|
"github.com/docker/containerd/runtime"
|
2015-12-19 00:54:02 +00:00
|
|
|
)
|
2015-12-01 18:55:13 +00:00
|
|
|
|
|
|
|
type ExitEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *ExitEvent) Handle(e *Event) error {
|
2015-12-19 00:54:02 +00:00
|
|
|
start := time.Now()
|
2016-01-06 21:32:46 +00:00
|
|
|
proc := e.Process
|
|
|
|
status, err := proc.ExitStatus()
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithField("error", err).Error("containerd: get exit status")
|
|
|
|
}
|
|
|
|
logrus.WithFields(logrus.Fields{"pid": proc.ID(), "status": status}).Debug("containerd: process exited")
|
|
|
|
|
|
|
|
// if the process is the the init process of the container then
|
|
|
|
// fire a separate event for this process
|
|
|
|
if proc.ID() != runtime.InitProcessID {
|
2015-12-01 23:49:24 +00:00
|
|
|
ne := NewEvent(ExecExitEventType)
|
2016-01-06 21:32:46 +00:00
|
|
|
ne.ID = proc.Container().ID()
|
2016-02-01 19:02:41 +00:00
|
|
|
ne.Pid = proc.ID()
|
2016-01-06 21:32:46 +00:00
|
|
|
ne.Status = status
|
2016-02-01 19:02:41 +00:00
|
|
|
ne.Process = proc
|
2015-12-01 23:49:24 +00:00
|
|
|
h.s.SendEvent(ne)
|
2016-01-06 21:32:46 +00:00
|
|
|
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
2016-01-06 21:32:46 +00:00
|
|
|
container := proc.Container()
|
2015-12-01 18:55:13 +00:00
|
|
|
ne := NewEvent(DeleteEventType)
|
|
|
|
ne.ID = container.ID()
|
2016-01-06 21:32:46 +00:00
|
|
|
ne.Status = status
|
|
|
|
ne.Pid = proc.ID()
|
2015-12-01 18:55:13 +00:00
|
|
|
h.s.SendEvent(ne)
|
2015-12-16 17:39:28 +00:00
|
|
|
|
2016-01-06 21:32:46 +00:00
|
|
|
// remove stats collection for container
|
2015-12-16 17:39:28 +00:00
|
|
|
stopCollect := NewEvent(StopStatsEventType)
|
|
|
|
stopCollect.ID = container.ID()
|
|
|
|
h.s.SendEvent(stopCollect)
|
2015-12-19 00:54:02 +00:00
|
|
|
ExitProcessTimer.UpdateSince(start)
|
2016-01-06 21:32:46 +00:00
|
|
|
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-12-01 23:49:24 +00:00
|
|
|
|
2015-12-10 20:30:04 +00:00
|
|
|
type ExecExitEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2015-12-01 23:49:24 +00:00
|
|
|
func (h *ExecExitEvent) Handle(e *Event) error {
|
2016-02-01 19:02:41 +00:00
|
|
|
container := e.Process.Container()
|
2015-12-01 23:49:24 +00:00
|
|
|
// exec process: we remove this process without notifying the main event loop
|
2016-02-01 19:02:41 +00:00
|
|
|
if err := container.RemoveProcess(e.Pid); err != nil {
|
|
|
|
logrus.WithField("error", err).Error("containerd: find container for pid")
|
|
|
|
}
|
|
|
|
h.s.notifySubscribers(e)
|
2015-12-01 23:49:24 +00:00
|
|
|
return nil
|
|
|
|
}
|