Skip to content

Commit b304c4e

Browse files
TP-Ondeloof
authored andcommitted
stop containers after termination
Signed-off-by: TP-O <[email protected]>
1 parent eca1365 commit b304c4e

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pkg/compose/up.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,26 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
7272
})
7373
}, s.stderr())
7474
}
75+
76+
var isTerminated bool
77+
eg, ctx := errgroup.WithContext(ctx)
7578
go func() {
7679
<-signalChan
80+
isTerminated = true
7781
printer.Cancel()
7882
fmt.Fprintln(s.stderr(), "Gracefully stopping... (press Ctrl+C again to force)")
79-
stopFunc() //nolint:errcheck
83+
eg.Go(stopFunc)
8084
}()
8185

8286
var exitCode int
83-
eg, ctx := errgroup.WithContext(ctx)
8487
eg.Go(func() error {
8588
code, err := printer.Run(options.Start.CascadeStop, options.Start.ExitCodeFrom, stopFunc)
8689
exitCode = code
8790
return err
8891
})
8992

9093
err = s.start(ctx, project.Name, options.Start, printer.HandleEvent)
91-
if err != nil {
94+
if err != nil && !isTerminated { // Ignore error if the process is terminated
9295
return err
9396
}
9497

0 commit comments

Comments
 (0)