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
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
type ExitTask struct {
|
2015-12-01 18:55:13 +00:00
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
func (h *ExitTask) Handle(e *Task) 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 {
|
2016-02-12 01:26:24 +00:00
|
|
|
ne := NewTask(ExecExitTaskType)
|
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
|
2016-02-12 01:26:24 +00:00
|
|
|
h.s.SendTask(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()
|
2016-02-12 01:26:24 +00:00
|
|
|
ne := NewTask(DeleteTaskType)
|
2015-12-01 18:55:13 +00:00
|
|
|
ne.ID = container.ID()
|
2016-01-06 21:32:46 +00:00
|
|
|
ne.Status = status
|
|
|
|
ne.Pid = proc.ID()
|
2016-02-12 01:26:24 +00:00
|
|
|
h.s.SendTask(ne)
|
2015-12-16 17:39:28 +00:00
|
|
|
|
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
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
type ExecExitTask struct {
|
2015-12-10 20:30:04 +00:00
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
func (h *ExecExitTask) Handle(e *Task) 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")
|
|
|
|
}
|
2016-02-12 01:26:24 +00:00
|
|
|
h.s.notifySubscribers(Event{
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
ID: e.ID,
|
|
|
|
Type: "exit",
|
|
|
|
Pid: e.Pid,
|
|
|
|
Status: e.Status,
|
|
|
|
})
|
2015-12-01 23:49:24 +00:00
|
|
|
return nil
|
|
|
|
}
|