| 55 | } |
| 56 | |
| 57 | func (c *Composer) stopContainers(ctx context.Context, containers []containerd.Container, opt StopOptions) error { |
| 58 | var timeoutArg string |
| 59 | if opt.Timeout != nil { |
| 60 | // `nerdctl stop` uses `--time` instead of `--timeout` |
| 61 | timeoutArg = fmt.Sprintf("--time=%d", *opt.Timeout) |
| 62 | } |
| 63 | |
| 64 | var rmWG sync.WaitGroup |
| 65 | for _, container := range containers { |
| 66 | container := container |
| 67 | rmWG.Add(1) |
| 68 | go func() { |
| 69 | defer rmWG.Done() |
| 70 | info, _ := container.Info(ctx, containerd.WithoutRefreshedMetadata) |
| 71 | log.G(ctx).Infof("Stopping container %s", info.Labels[labels.Name]) |
| 72 | args := []string{"stop"} |
| 73 | if opt.Timeout != nil { |
| 74 | args = append(args, timeoutArg) |
| 75 | } |
| 76 | args = append(args, container.ID()) |
| 77 | if err := c.runNerdctlCmd(ctx, args...); err != nil { |
| 78 | log.G(ctx).Warn(err) |
| 79 | } |
| 80 | }() |
| 81 | } |
| 82 | rmWG.Wait() |
| 83 | |
| 84 | return nil |
| 85 | } |
| 86 | |
| 87 | func (c *Composer) stopContainersFromParsedServices(ctx context.Context, containers map[string]serviceparser.Container) { |
| 88 | var rmWG sync.WaitGroup |