7 "github.com/Sirupsen/logrus"
8 "github.com/containerd/containerd/runtime"
9 "golang.org/x/net/context"
13 type Worker interface {
17 type startTask struct {
18 Container runtime.Container
24 StartResponse chan StartResponse
28 // NewWorker return a new initialized worker
29 func NewWorker(s *Supervisor, wg *sync.WaitGroup) Worker {
41 // Start runs a loop in charge of starting new containers
42 func (w *worker) Start() {
44 for t := range w.s.startTasks {
46 process, err := t.Container.Start(t.Ctx, t.CheckpointPath, runtime.NewStdio(t.Stdin, t.Stdout, t.Stderr))
48 logrus.WithFields(logrus.Fields{
50 "id": t.Container.ID(),
51 }).Error("containerd: start container")
61 if err := w.s.monitor.MonitorOOM(t.Container); err != nil && err != runtime.ErrContainerExited {
62 if process.State() != runtime.Stopped {
63 logrus.WithField("error", err).Error("containerd: notify OOM events")
66 if err := w.s.monitorProcess(process); err != nil {
67 logrus.WithField("error", err).Error("containerd: add process to monitor")
77 // only call process start if we aren't restoring from a checkpoint
78 // if we have restored from a checkpoint then the process is already started
79 if t.CheckpointPath == "" {
80 if err := process.Start(); err != nil {
81 logrus.WithField("error", err).Error("containerd: start init process")
92 ContainerStartTimer.UpdateSince(started)
93 w.s.newExecSyncMap(t.Container.ID())
95 t.StartResponse <- StartResponse{
96 Container: t.Container,
98 w.s.notifySubscribers(Event{
99 Timestamp: time.Now(),
100 ID: t.Container.ID(),