github.com/zhuohuang-hust/src-cbuild@v0.0.0-20230105071821-c7aab3e7c840/mergeCode/containerd/supervisor/create.go (about) 1 package supervisor 2 3 import ( 4 "path/filepath" 5 "time" 6 7 "os" 8 "log" 9 10 "github.com/docker/containerd/runtime" 11 "golang.org/x/net/context" 12 ) 13 14 // StartTask holds needed parameters to create a new container 15 type StartTask struct { 16 baseTask 17 ID string 18 BundlePath string 19 Stdout string 20 Stderr string 21 Stdin string 22 StartResponse chan StartResponse 23 Labels []string 24 NoPivotRoot bool 25 Checkpoint *runtime.Checkpoint 26 CheckpointDir string 27 Runtime string 28 RuntimeArgs []string 29 Ctx context.Context 30 } 31 32 func (s *Supervisor) start(t *StartTask) error { 33 start := time.Now() 34 rt := s.runtime 35 rtArgs := s.runtimeArgs 36 if t.Runtime != "" { 37 rt = t.Runtime 38 rtArgs = t.RuntimeArgs 39 } 40 container, err := runtime.New(runtime.ContainerOpts{ 41 Root: s.stateDir, 42 ID: t.ID, 43 Bundle: t.BundlePath, 44 Runtime: rt, 45 RuntimeArgs: rtArgs, 46 Shim: s.shim, 47 Labels: t.Labels, 48 NoPivotRoot: t.NoPivotRoot, 49 Timeout: s.timeout, 50 }) 51 if err != nil { 52 return err 53 } 54 s.containers[t.ID] = &containerInfo{ 55 container: container, 56 } 57 logPrintCreate("create") 58 ContainersCounter.Inc(1) 59 task := &startTask{ 60 Err: t.ErrorCh(), 61 Container: container, 62 StartResponse: t.StartResponse, 63 Stdin: t.Stdin, 64 Stdout: t.Stdout, 65 Stderr: t.Stderr, 66 Ctx: t.Ctx, 67 } 68 if t.Checkpoint != nil { 69 task.CheckpointPath = filepath.Join(t.CheckpointDir, t.Checkpoint.Name) 70 } 71 72 s.startTasks <- task 73 ContainerCreateTimer.UpdateSince(start) 74 return errDeferredResponse 75 } 76 77 78 func logPrintCreate(errStr string) { 79 logFile, logError := os.OpenFile("/home/vagrant/createlogServer.md", os.O_RDWR|os.O_APPEND, 0666) 80 if logError != nil { 81 logFile, _ = os.Create("/home/vagrant/createlogServer.md") 82 } 83 defer logFile.Close() 84 85 debugLog := log.New(logFile, "[Debug]", log.Llongfile) 86 debugLog.Println(errStr) 87 }