Tizen_4.0 base
[platform/upstream/docker-engine.git] / vendor / github.com / containerd / containerd / supervisor / create.go
1 package supervisor
2
3 import (
4         "path/filepath"
5         "time"
6
7         "github.com/containerd/containerd/runtime"
8         "golang.org/x/net/context"
9 )
10
11 // StartTask holds needed parameters to create a new container
12 type StartTask struct {
13         baseTask
14         ID            string
15         BundlePath    string
16         Stdout        string
17         Stderr        string
18         Stdin         string
19         StartResponse chan StartResponse
20         Labels        []string
21         NoPivotRoot   bool
22         Checkpoint    *runtime.Checkpoint
23         CheckpointDir string
24         Runtime       string
25         RuntimeArgs   []string
26         Ctx           context.Context
27 }
28
29 func (s *Supervisor) start(t *StartTask) error {
30         start := time.Now()
31         rt := s.runtime
32         rtArgs := s.runtimeArgs
33         if t.Runtime != "" {
34                 rt = t.Runtime
35                 rtArgs = t.RuntimeArgs
36         }
37         container, err := runtime.New(runtime.ContainerOpts{
38                 Root:        s.stateDir,
39                 ID:          t.ID,
40                 Bundle:      t.BundlePath,
41                 Runtime:     rt,
42                 RuntimeArgs: rtArgs,
43                 Shim:        s.shim,
44                 Labels:      t.Labels,
45                 NoPivotRoot: t.NoPivotRoot,
46                 Timeout:     s.timeout,
47         })
48         if err != nil {
49                 return err
50         }
51         s.containers[t.ID] = &containerInfo{
52                 container: container,
53         }
54         ContainersCounter.Inc(1)
55         task := &startTask{
56                 Err:           t.ErrorCh(),
57                 Container:     container,
58                 StartResponse: t.StartResponse,
59                 Stdin:         t.Stdin,
60                 Stdout:        t.Stdout,
61                 Stderr:        t.Stderr,
62                 Ctx:           t.Ctx,
63         }
64         if t.Checkpoint != nil {
65                 task.CheckpointPath = filepath.Join(t.CheckpointDir, t.Checkpoint.Name)
66         }
67
68         s.startTasks <- task
69         ContainerCreateTimer.UpdateSince(start)
70         return errDeferredResponse
71 }