create.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. package supervisor
  2. import (
  3. "path/filepath"
  4. "time"
  5. "github.com/docker/containerd/runtime"
  6. )
  7. type StartTask struct {
  8. baseTask
  9. ID string
  10. BundlePath string
  11. Stdout string
  12. Stderr string
  13. Stdin string
  14. StartResponse chan StartResponse
  15. Labels []string
  16. NoPivotRoot bool
  17. Checkpoint *runtime.Checkpoint
  18. CheckpointDir string
  19. Runtime string
  20. RuntimeArgs []string
  21. }
  22. func (s *Supervisor) start(t *StartTask) error {
  23. start := time.Now()
  24. rt := s.runtime
  25. rtArgs := s.runtimeArgs
  26. if t.Runtime != "" {
  27. rt = t.Runtime
  28. rtArgs = t.RuntimeArgs
  29. }
  30. container, err := runtime.New(runtime.ContainerOpts{
  31. Root: s.stateDir,
  32. ID: t.ID,
  33. Bundle: t.BundlePath,
  34. Runtime: rt,
  35. RuntimeArgs: rtArgs,
  36. Shim: s.shim,
  37. Labels: t.Labels,
  38. NoPivotRoot: t.NoPivotRoot,
  39. Timeout: s.timeout,
  40. })
  41. if err != nil {
  42. return err
  43. }
  44. s.containers[t.ID] = &containerInfo{
  45. container: container,
  46. }
  47. ContainersCounter.Inc(1)
  48. task := &startTask{
  49. Err: t.ErrorCh(),
  50. Container: container,
  51. StartResponse: t.StartResponse,
  52. Stdin: t.Stdin,
  53. Stdout: t.Stdout,
  54. Stderr: t.Stderr,
  55. }
  56. if t.Checkpoint != nil {
  57. task.CheckpointPath = filepath.Join(t.CheckpointDir, t.Checkpoint.Name)
  58. }
  59. s.startTasks <- task
  60. ContainerCreateTimer.UpdateSince(start)
  61. return errDeferredResponse
  62. }