add_process.go 912 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package supervisor
  2. import (
  3. "time"
  4. "github.com/docker/containerd/runtime"
  5. "github.com/docker/containerd/specs"
  6. )
  7. type AddProcessTask struct {
  8. baseTask
  9. ID string
  10. PID string
  11. Stdout string
  12. Stderr string
  13. Stdin string
  14. ProcessSpec *specs.ProcessSpec
  15. StartResponse chan StartResponse
  16. }
  17. func (s *Supervisor) addProcess(t *AddProcessTask) error {
  18. start := time.Now()
  19. ci, ok := s.containers[t.ID]
  20. if !ok {
  21. return ErrContainerNotFound
  22. }
  23. process, err := ci.container.Exec(t.PID, *t.ProcessSpec, runtime.NewStdio(t.Stdin, t.Stdout, t.Stderr))
  24. if err != nil {
  25. return err
  26. }
  27. if err := s.monitorProcess(process); err != nil {
  28. return err
  29. }
  30. ExecProcessTimer.UpdateSince(start)
  31. t.StartResponse <- StartResponse{}
  32. s.notifySubscribers(Event{
  33. Timestamp: time.Now(),
  34. Type: StateStartProcess,
  35. PID: t.PID,
  36. ID: t.ID,
  37. })
  38. return nil
  39. }