2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2015-12-19 00:54:02 +00:00
|
|
|
import (
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
)
|
2015-12-11 01:07:21 +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 {
|
2015-12-19 00:54:02 +00:00
|
|
|
start := time.Now()
|
2015-12-11 19:27:33 +00:00
|
|
|
ci, ok := h.s.containers[e.ID]
|
2015-12-01 18:55:13 +00:00
|
|
|
if !ok {
|
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
2015-12-15 19:43:51 +00:00
|
|
|
p, io, err := h.s.runtime.StartProcess(ci.container, *e.Process, e.Console)
|
2015-12-01 18:55:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2015-12-15 19:43:51 +00:00
|
|
|
if e.Pid, err = p.Pid(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
h.s.processes[e.Pid] = &containerInfo{
|
|
|
|
container: ci.container,
|
|
|
|
}
|
2015-12-14 22:40:50 +00:00
|
|
|
l, err := h.s.copyIO(e.Stdin, e.Stdout, e.Stderr, io)
|
2015-12-11 19:27:33 +00:00
|
|
|
if err != nil {
|
2015-12-11 01:07:21 +00:00
|
|
|
// log the error but continue with the other commands
|
|
|
|
logrus.WithFields(logrus.Fields{
|
|
|
|
"error": err,
|
|
|
|
"id": e.ID,
|
|
|
|
}).Error("log stdio")
|
|
|
|
}
|
2015-12-15 19:43:51 +00:00
|
|
|
h.s.processes[e.Pid].copier = l
|
2015-12-19 00:54:02 +00:00
|
|
|
ExecProcessTimer.UpdateSince(start)
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|