2015-12-01 18:55:13 +00:00
|
|
|
package containerd
|
|
|
|
|
|
|
|
import "github.com/Sirupsen/logrus"
|
|
|
|
|
|
|
|
type ExitEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2015-12-01 23:49:24 +00:00
|
|
|
type ExecExitEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2015-12-01 18:55:13 +00:00
|
|
|
func (h *ExitEvent) Handle(e *Event) error {
|
|
|
|
logrus.WithFields(logrus.Fields{"pid": e.Pid, "status": e.Status}).
|
|
|
|
Debug("containerd: process exited")
|
|
|
|
// is it the child process of a container
|
|
|
|
if container, ok := h.s.processes[e.Pid]; ok {
|
2015-12-01 23:49:24 +00:00
|
|
|
ne := NewEvent(ExecExitEventType)
|
|
|
|
ne.ID = container.ID()
|
|
|
|
ne.Pid = e.Pid
|
|
|
|
ne.Status = e.Status
|
|
|
|
h.s.SendEvent(ne)
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-12-01 23:49:24 +00:00
|
|
|
|
2015-12-01 18:55:13 +00:00
|
|
|
// is it the main container's process
|
|
|
|
container, err := h.s.getContainerForPid(e.Pid)
|
|
|
|
if err != nil {
|
|
|
|
if err != errNoContainerForPid {
|
|
|
|
logrus.WithField("error", err).Error("containerd: find container for pid")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
container.SetExited(e.Status)
|
|
|
|
ne := NewEvent(DeleteEventType)
|
|
|
|
ne.ID = container.ID()
|
|
|
|
h.s.SendEvent(ne)
|
|
|
|
return nil
|
|
|
|
}
|
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
|
|
|
|
container := h.s.processes[e.Pid]
|
|
|
|
if err := container.RemoveProcess(e.Pid); err != nil {
|
|
|
|
logrus.WithField("error", err).Error("containerd: find container for pid")
|
|
|
|
}
|
|
|
|
delete(h.s.processes, e.Pid)
|
|
|
|
h.s.NotifySubscribers(e)
|
|
|
|
return nil
|
|
|
|
}
|