2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2016-02-01 19:02:41 +00:00
|
|
|
import "time"
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
process, err := ci.container.Exec(e.Pid, *e.ProcessSpec)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if err := h.s.monitorProcess(process); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
ExecProcessTimer.UpdateSince(start)
|
|
|
|
e.StartResponse <- StartResponse{
|
|
|
|
Stdin: process.Stdin(),
|
|
|
|
Stdout: process.Stdout(),
|
|
|
|
Stderr: process.Stderr(),
|
|
|
|
}
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|