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 {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
|
|
|
Process runtime.Process
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) exit(t *ExitTask) error {
|
2015-12-19 00:54:02 +00:00
|
|
|
start := time.Now()
|
2016-02-17 18:55:54 +00:00
|
|
|
proc := t.Process
|
2016-01-06 21:32:46 +00:00
|
|
|
status, err := proc.ExitStatus()
|
|
|
|
if err != nil {
|
2016-02-25 20:59:34 +00:00
|
|
|
logrus.WithFields(logrus.Fields{
|
|
|
|
"error": err,
|
|
|
|
"pid": proc.ID(),
|
|
|
|
"id": proc.Container().ID(),
|
|
|
|
"systemPid": proc.SystemPid(),
|
|
|
|
}).Error("containerd: get exit status")
|
2016-01-06 21:32:46 +00:00
|
|
|
}
|
2016-02-25 20:59:34 +00:00
|
|
|
logrus.WithFields(logrus.Fields{
|
|
|
|
"pid": proc.ID(),
|
|
|
|
"status": status,
|
|
|
|
"id": proc.Container().ID(),
|
|
|
|
"systemPid": proc.SystemPid(),
|
|
|
|
}).Debug("containerd: process exited")
|
2016-01-06 21:32:46 +00:00
|
|
|
|
|
|
|
// 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-17 18:55:54 +00:00
|
|
|
ne := &ExecExitTask{
|
|
|
|
ID: proc.Container().ID(),
|
|
|
|
PID: proc.ID(),
|
|
|
|
Status: status,
|
|
|
|
Process: proc,
|
|
|
|
}
|
|
|
|
s.SendTask(ne)
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
2016-01-06 21:32:46 +00:00
|
|
|
container := proc.Container()
|
2016-02-17 18:55:54 +00:00
|
|
|
ne := &DeleteTask{
|
|
|
|
ID: container.ID(),
|
|
|
|
Status: status,
|
|
|
|
PID: proc.ID(),
|
|
|
|
}
|
|
|
|
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 {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
|
|
|
ID string
|
|
|
|
PID string
|
|
|
|
Status int
|
|
|
|
Process runtime.Process
|
2015-12-10 20:30:04 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) execExit(t *ExecExitTask) error {
|
|
|
|
container := t.Process.Container()
|
2015-12-01 23:49:24 +00:00
|
|
|
// exec process: we remove this process without notifying the main event loop
|
2016-02-17 18:55:54 +00:00
|
|
|
if err := container.RemoveProcess(t.PID); err != nil {
|
2016-02-01 19:02:41 +00:00
|
|
|
logrus.WithField("error", err).Error("containerd: find container for pid")
|
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
s.notifySubscribers(Event{
|
2016-02-12 01:26:24 +00:00
|
|
|
Timestamp: time.Now(),
|
2016-02-17 18:55:54 +00:00
|
|
|
ID: t.ID,
|
2016-02-12 01:26:24 +00:00
|
|
|
Type: "exit",
|
2016-02-17 18:55:54 +00:00
|
|
|
PID: t.PID,
|
|
|
|
Status: t.Status,
|
2016-02-12 01:26:24 +00:00
|
|
|
})
|
2015-12-01 23:49:24 +00:00
|
|
|
return nil
|
|
|
|
}
|