2015-12-03 01:42:28 +00:00
|
|
|
package containerd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Worker interface {
|
|
|
|
Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
type StartTask struct {
|
2015-12-04 00:07:53 +00:00
|
|
|
Container runtime.Container
|
2015-12-04 22:00:07 +00:00
|
|
|
Checkpoint string
|
2015-12-11 01:07:21 +00:00
|
|
|
IO *runtime.IO
|
2015-12-14 22:40:50 +00:00
|
|
|
Stdin string
|
2015-12-14 22:15:26 +00:00
|
|
|
Stdout string
|
|
|
|
Stderr string
|
2015-12-04 00:07:53 +00:00
|
|
|
Err chan error
|
2015-12-03 01:42:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewWorker(s *Supervisor, wg *sync.WaitGroup) Worker {
|
|
|
|
return &worker{
|
|
|
|
s: s,
|
|
|
|
wg: wg,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type worker struct {
|
|
|
|
wg *sync.WaitGroup
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
|
|
|
func (w *worker) Start() {
|
|
|
|
defer w.wg.Done()
|
|
|
|
for t := range w.s.tasks {
|
|
|
|
started := time.Now()
|
2015-12-14 22:40:50 +00:00
|
|
|
l, err := w.s.copyIO(t.Stdin, t.Stdout, t.Stderr, t.IO)
|
2015-12-11 19:27:33 +00:00
|
|
|
if err != nil {
|
2015-12-11 01:07:21 +00:00
|
|
|
evt := NewEvent(DeleteEventType)
|
|
|
|
evt.ID = t.Container.ID()
|
|
|
|
w.s.SendEvent(evt)
|
|
|
|
t.Err <- err
|
|
|
|
continue
|
|
|
|
}
|
2015-12-14 22:15:26 +00:00
|
|
|
w.s.containers[t.Container.ID()].copier = l
|
2015-12-04 22:00:07 +00:00
|
|
|
if t.Checkpoint != "" {
|
|
|
|
if err := t.Container.Restore(t.Checkpoint); err != nil {
|
2015-12-04 00:07:53 +00:00
|
|
|
evt := NewEvent(DeleteEventType)
|
|
|
|
evt.ID = t.Container.ID()
|
|
|
|
w.s.SendEvent(evt)
|
|
|
|
t.Err <- err
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if err := t.Container.Start(); err != nil {
|
|
|
|
evt := NewEvent(DeleteEventType)
|
|
|
|
evt.ID = t.Container.ID()
|
|
|
|
w.s.SendEvent(evt)
|
|
|
|
t.Err <- err
|
|
|
|
continue
|
|
|
|
}
|
2015-12-03 01:42:28 +00:00
|
|
|
}
|
|
|
|
ContainerStartTimer.UpdateSince(started)
|
|
|
|
t.Err <- nil
|
|
|
|
}
|
|
|
|
}
|