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"
|
|
|
|
)
|
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()
|
2015-12-01 18:55:13 +00:00
|
|
|
logrus.WithFields(logrus.Fields{"pid": e.Pid, "status": e.Status}).
|
|
|
|
Debug("containerd: process exited")
|
|
|
|
// is it the child process of a container
|
2015-12-11 19:27:33 +00:00
|
|
|
if info, ok := h.s.processes[e.Pid]; ok {
|
2015-12-01 23:49:24 +00:00
|
|
|
ne := NewEvent(ExecExitEventType)
|
2015-12-11 19:27:33 +00:00
|
|
|
ne.ID = info.container.ID()
|
2015-12-01 23:49:24 +00:00
|
|
|
ne.Pid = e.Pid
|
|
|
|
ne.Status = e.Status
|
|
|
|
h.s.SendEvent(ne)
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
// is it the main container's process
|
|
|
|
container, err := h.s.getContainerForPid(e.Pid)
|
|
|
|
if err != nil {
|
|
|
|
if err != errNoContainerForPid {
|
2015-12-15 19:43:51 +00:00
|
|
|
logrus.WithField("error", err).Error("containerd: find containers main pid")
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
container.SetExited(e.Status)
|
|
|
|
ne := NewEvent(DeleteEventType)
|
|
|
|
ne.ID = container.ID()
|
2015-12-10 20:30:04 +00:00
|
|
|
ne.Pid = e.Pid
|
|
|
|
ne.Status = e.Status
|
2015-12-01 18:55:13 +00:00
|
|
|
h.s.SendEvent(ne)
|
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)
|
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 {
|
|
|
|
// exec process: we remove this process without notifying the main event loop
|
2015-12-11 19:27:33 +00:00
|
|
|
info := h.s.processes[e.Pid]
|
|
|
|
if err := info.container.RemoveProcess(e.Pid); err != nil {
|
2015-12-01 23:49:24 +00:00
|
|
|
logrus.WithField("error", err).Error("containerd: find container for pid")
|
|
|
|
}
|
2015-12-14 22:15:26 +00:00
|
|
|
if err := info.copier.Close(); err != nil {
|
2015-12-11 19:27:33 +00:00
|
|
|
logrus.WithField("error", err).Error("containerd: close process IO")
|
|
|
|
}
|
2015-12-01 23:49:24 +00:00
|
|
|
delete(h.s.processes, e.Pid)
|
2015-12-10 22:11:00 +00:00
|
|
|
h.s.notifySubscribers(e)
|
2015-12-01 23:49:24 +00:00
|
|
|
return nil
|
|
|
|
}
|