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-29 18:48:39 +00:00
|
|
|
"github.com/docker/containerd/specs"
|
2016-02-03 21:56:15 +00:00
|
|
|
)
|
2016-02-01 19:02:41 +00:00
|
|
|
|
2016-02-12 01:26:24 +00:00
|
|
|
type AddProcessTask struct {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
|
|
|
ID string
|
|
|
|
PID string
|
|
|
|
Stdout string
|
|
|
|
Stderr string
|
|
|
|
Stdin string
|
2016-02-29 18:48:39 +00:00
|
|
|
ProcessSpec *specs.ProcessSpec
|
2016-02-17 18:55:54 +00:00
|
|
|
StartResponse chan StartResponse
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) addProcess(t *AddProcessTask) error {
|
2016-02-01 19:02:41 +00:00
|
|
|
start := time.Now()
|
2016-02-17 18:55:54 +00:00
|
|
|
ci, ok := s.containers[t.ID]
|
2016-02-01 19:02:41 +00:00
|
|
|
if !ok {
|
|
|
|
return ErrContainerNotFound
|
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
process, err := ci.container.Exec(t.PID, *t.ProcessSpec, runtime.NewStdio(t.Stdin, t.Stdout, t.Stderr))
|
2016-02-01 19:02:41 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
if err := s.monitorProcess(process); err != nil {
|
2016-02-01 19:02:41 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
ExecProcessTimer.UpdateSince(start)
|
2016-02-17 18:55:54 +00:00
|
|
|
t.StartResponse <- StartResponse{}
|
|
|
|
s.notifySubscribers(Event{
|
2016-02-12 01:26:24 +00:00
|
|
|
Timestamp: time.Now(),
|
|
|
|
Type: "start-process",
|
2016-02-17 18:55:54 +00:00
|
|
|
PID: t.PID,
|
|
|
|
ID: t.ID,
|
2016-02-12 01:26:24 +00:00
|
|
|
})
|
2015-12-01 18:55:13 +00:00
|
|
|
return nil
|
|
|
|
}
|