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-06-03 22:00:49 +00:00
|
|
|
// ExitTask holds needed parameters to execute the exit task
|
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 {
|
|
|
|
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,
|
|
|
|
}
|
2016-07-13 18:01:07 +00:00
|
|
|
s.execExit(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{
|
2016-07-15 18:49:43 +00:00
|
|
|
ID: container.ID(),
|
|
|
|
Status: status,
|
|
|
|
PID: proc.ID(),
|
|
|
|
Process: proc,
|
2016-02-17 18:55:54 +00:00
|
|
|
}
|
2016-07-13 18:01:07 +00:00
|
|
|
s.delete(ne)
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-12-01 23:49:24 +00:00
|
|
|
|
2016-06-03 22:00:49 +00:00
|
|
|
// ExecExitTask holds needed parameters to execute the exec exit task
|
2016-02-12 01:26:24 +00:00
|
|
|
type ExecExitTask struct {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
|
|
|
ID string
|
|
|
|
PID string
|
2016-09-19 18:46:33 +00:00
|
|
|
Status uint32
|
2016-02-17 18:55:54 +00:00
|
|
|
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-09-12 18:19:54 +00:00
|
|
|
// If the exec spawned children which are still using its IO
|
|
|
|
// waiting here will block until they die or close their IO
|
|
|
|
// descriptors.
|
|
|
|
// Hence, we use a go routine to avoid block all other operations
|
|
|
|
go func() {
|
|
|
|
t.Process.Wait()
|
|
|
|
s.notifySubscribers(Event{
|
|
|
|
Timestamp: time.Now(),
|
|
|
|
ID: t.ID,
|
|
|
|
Type: StateExit,
|
|
|
|
PID: t.PID,
|
|
|
|
Status: t.Status,
|
|
|
|
})
|
|
|
|
}()
|
2015-12-01 23:49:24 +00:00
|
|
|
return nil
|
|
|
|
}
|