2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-03 01:42:28 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"sync"
|
|
|
|
"time"
|
|
|
|
|
2015-12-16 00:22:53 +00:00
|
|
|
"github.com/Sirupsen/logrus"
|
2015-12-03 01:42:28 +00:00
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Worker interface {
|
|
|
|
Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
type StartTask struct {
|
2015-12-16 00:22:53 +00:00
|
|
|
Container runtime.Container
|
|
|
|
Checkpoint string
|
|
|
|
IO *runtime.IO
|
|
|
|
Stdin string
|
|
|
|
Stdout string
|
|
|
|
Stderr string
|
|
|
|
Err chan error
|
|
|
|
StartResponse chan StartResponse
|
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 {
|
2016-01-06 21:32:46 +00:00
|
|
|
var (
|
|
|
|
err error
|
|
|
|
process runtime.Process
|
|
|
|
started = time.Now()
|
|
|
|
)
|
2015-12-04 22:00:07 +00:00
|
|
|
if t.Checkpoint != "" {
|
2016-01-06 21:32:46 +00:00
|
|
|
/*
|
|
|
|
if err := t.Container.Restore(t.Checkpoint); err != nil {
|
|
|
|
evt := NewEvent(DeleteEventType)
|
|
|
|
evt.ID = t.Container.ID()
|
|
|
|
w.s.SendEvent(evt)
|
|
|
|
t.Err <- err
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
*/
|
2015-12-04 00:07:53 +00:00
|
|
|
} else {
|
2016-01-06 21:32:46 +00:00
|
|
|
process, err = t.Container.Start()
|
|
|
|
if 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
|
|
|
|
}
|
2015-12-03 01:42:28 +00:00
|
|
|
}
|
2016-01-06 21:32:46 +00:00
|
|
|
/*
|
|
|
|
if w.s.notifier != nil {
|
|
|
|
n, err := t.Container.OOM()
|
|
|
|
if err != nil {
|
|
|
|
logrus.WithField("error", err).Error("containerd: notify OOM events")
|
|
|
|
} else {
|
|
|
|
w.s.notifier.Add(n, t.Container.ID())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if err := w.s.monitorProcess(process); err != nil {
|
|
|
|
logrus.WithField("error", err).Error("containerd: add process to monitor")
|
2015-12-16 00:22:53 +00:00
|
|
|
}
|
2015-12-03 01:42:28 +00:00
|
|
|
ContainerStartTimer.UpdateSince(started)
|
|
|
|
t.Err <- nil
|
2015-12-16 00:22:53 +00:00
|
|
|
t.StartResponse <- StartResponse{
|
2016-01-06 21:32:46 +00:00
|
|
|
Stdin: process.Stdin(),
|
|
|
|
Stdout: process.Stdout(),
|
|
|
|
Stderr: process.Stderr(),
|
2015-12-16 00:22:53 +00:00
|
|
|
}
|
2015-12-03 01:42:28 +00:00
|
|
|
}
|
|
|
|
}
|