2015-12-18 00:07:04 +00:00
|
|
|
package supervisor
|
2015-12-01 18:55:13 +00:00
|
|
|
|
2016-01-06 21:32:46 +00:00
|
|
|
import (
|
2016-05-26 00:42:37 +00:00
|
|
|
"path/filepath"
|
2016-01-06 21:32:46 +00:00
|
|
|
|
|
|
|
"github.com/docker/containerd/runtime"
|
|
|
|
)
|
2015-12-19 00:54:02 +00:00
|
|
|
|
2016-06-03 22:00:49 +00:00
|
|
|
// StartTask holds needed parameters to create a new container
|
2016-02-12 01:26:24 +00:00
|
|
|
type StartTask struct {
|
2016-02-17 18:55:54 +00:00
|
|
|
baseTask
|
|
|
|
ID string
|
|
|
|
BundlePath string
|
|
|
|
Stdout string
|
|
|
|
Stderr string
|
|
|
|
Stdin string
|
|
|
|
StartResponse chan StartResponse
|
|
|
|
Labels []string
|
2016-03-30 21:25:42 +00:00
|
|
|
NoPivotRoot bool
|
2016-04-26 20:29:35 +00:00
|
|
|
Checkpoint *runtime.Checkpoint
|
2016-05-26 00:42:37 +00:00
|
|
|
CheckpointDir string
|
2016-05-23 22:43:47 +00:00
|
|
|
Runtime string
|
|
|
|
RuntimeArgs []string
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
func (s *Supervisor) start(t *StartTask) error {
|
2016-05-23 22:43:47 +00:00
|
|
|
rt := s.runtime
|
|
|
|
rtArgs := s.runtimeArgs
|
|
|
|
if t.Runtime != "" {
|
|
|
|
rt = t.Runtime
|
|
|
|
rtArgs = t.RuntimeArgs
|
|
|
|
}
|
2016-03-30 21:25:42 +00:00
|
|
|
container, err := runtime.New(runtime.ContainerOpts{
|
|
|
|
Root: s.stateDir,
|
|
|
|
ID: t.ID,
|
|
|
|
Bundle: t.BundlePath,
|
2016-05-23 22:43:47 +00:00
|
|
|
Runtime: rt,
|
|
|
|
RuntimeArgs: rtArgs,
|
2016-04-06 06:42:47 +00:00
|
|
|
Shim: s.shim,
|
2016-03-30 21:25:42 +00:00
|
|
|
Labels: t.Labels,
|
|
|
|
NoPivotRoot: t.NoPivotRoot,
|
2016-03-28 20:30:37 +00:00
|
|
|
Timeout: s.timeout,
|
2016-03-30 21:25:42 +00:00
|
|
|
})
|
2015-12-01 18:55:13 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-02-17 18:55:54 +00:00
|
|
|
s.containers[t.ID] = &containerInfo{
|
2015-12-11 19:27:33 +00:00
|
|
|
container: container,
|
|
|
|
}
|
2016-02-12 01:26:24 +00:00
|
|
|
task := &startTask{
|
2016-02-17 18:55:54 +00:00
|
|
|
Err: t.ErrorCh(),
|
2015-12-16 00:22:53 +00:00
|
|
|
Container: container,
|
2016-02-17 18:55:54 +00:00
|
|
|
StartResponse: t.StartResponse,
|
|
|
|
Stdin: t.Stdin,
|
|
|
|
Stdout: t.Stdout,
|
|
|
|
Stderr: t.Stderr,
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|
2016-04-26 20:29:35 +00:00
|
|
|
if t.Checkpoint != nil {
|
2016-05-26 00:42:37 +00:00
|
|
|
task.CheckpointPath = filepath.Join(t.CheckpointDir, t.Checkpoint.Name)
|
2016-04-26 20:29:35 +00:00
|
|
|
}
|
2016-02-26 03:18:10 +00:00
|
|
|
|
2016-02-17 18:55:54 +00:00
|
|
|
s.startTasks <- task
|
2016-04-02 17:28:05 +00:00
|
|
|
return errDeferredResponse
|
2015-12-01 18:55:13 +00:00
|
|
|
}
|