2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2016-02-03 21:56:15 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
2016-02-01 19:02:41 +00:00
|
|
|
|
2015-12-01 18:55:13 +00:00
|
|
|
type AddProcessEvent struct {
|
|
|
|
s *Supervisor
|
|
|
|
}
|
|
|
|
|
2015-12-11 01:07:21 +00:00
|
|
|
// TODO: add this to worker for concurrent starts??? maybe not because of races where the container
|
|
|
|
// could be stopped and removed...
|
2015-12-01 18:55:13 +00:00
|
|
|
func (h *AddProcessEvent) Handle(e *Event) error {
|
2016-02-01 19:02:41 +00:00
|
|
|
start := time.Now()
|
|
|
|
ci, ok := h.s.containers[e.ID]
|
|
|
|
if !ok {
|
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
2016-02-11 20:20:29 +00:00
|
|
|
process, err := ci.container.Exec(e.Pid, *e.ProcessSpec, runtime.NewStdio(e.Stdin, e.Stdout, e.Stderr))
|
2016-02-01 19:02:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := h.s.monitorProcess(process); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ExecProcessTimer.UpdateSince(start)
|
2016-02-03 21:56:15 +00:00
|
|
|
e.StartResponse <- StartResponse{}
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|