exit.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package supervisor
  2. import (
  3. "time"
  4. "github.com/Sirupsen/logrus"
  5. "github.com/docker/containerd/runtime"
  6. )
  7. type ExitTask struct {
  8. baseTask
  9. Process runtime.Process
  10. }
  11. func (s *Supervisor) exit(t *ExitTask) error {
  12. start := time.Now()
  13. proc := t.Process
  14. status, err := proc.ExitStatus()
  15. if err != nil {
  16. logrus.WithFields(logrus.Fields{
  17. "error": err,
  18. "pid": proc.ID(),
  19. "id": proc.Container().ID(),
  20. "systemPid": proc.SystemPid(),
  21. }).Error("containerd: get exit status")
  22. }
  23. logrus.WithFields(logrus.Fields{
  24. "pid": proc.ID(),
  25. "status": status,
  26. "id": proc.Container().ID(),
  27. "systemPid": proc.SystemPid(),
  28. }).Debug("containerd: process exited")
  29. // if the process is the the init process of the container then
  30. // fire a separate event for this process
  31. if proc.ID() != runtime.InitProcessID {
  32. ne := &ExecExitTask{
  33. ID: proc.Container().ID(),
  34. PID: proc.ID(),
  35. Status: status,
  36. Process: proc,
  37. }
  38. s.SendTask(ne)
  39. return nil
  40. }
  41. container := proc.Container()
  42. ne := &DeleteTask{
  43. ID: container.ID(),
  44. Status: status,
  45. PID: proc.ID(),
  46. }
  47. s.SendTask(ne)
  48. ExitProcessTimer.UpdateSince(start)
  49. return nil
  50. }
  51. type ExecExitTask struct {
  52. baseTask
  53. ID string
  54. PID string
  55. Status int
  56. Process runtime.Process
  57. }
  58. func (s *Supervisor) execExit(t *ExecExitTask) error {
  59. container := t.Process.Container()
  60. // exec process: we remove this process without notifying the main event loop
  61. if err := container.RemoveProcess(t.PID); err != nil {
  62. logrus.WithField("error", err).Error("containerd: find container for pid")
  63. }
  64. s.notifySubscribers(Event{
  65. Timestamp: time.Now(),
  66. ID: t.ID,
  67. Type: StateExit,
  68. PID: t.PID,
  69. Status: t.Status,
  70. })
  71. return nil
  72. }