mirror of https://github.com/docker/compose.git
stop containers after termination
Signed-off-by: TP-O <letranphong2k1@gmail.com>
This commit is contained in:
parent
eca1365d42
commit
b304c4e154
|
@ -72,15 +72,18 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||
})
|
||||
}, s.stderr())
|
||||
}
|
||||
|
||||
var isTerminated bool
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
go func() {
|
||||
<-signalChan
|
||||
isTerminated = true
|
||||
printer.Cancel()
|
||||
fmt.Fprintln(s.stderr(), "Gracefully stopping... (press Ctrl+C again to force)")
|
||||
stopFunc() //nolint:errcheck
|
||||
eg.Go(stopFunc)
|
||||
}()
|
||||
|
||||
var exitCode int
|
||||
eg, ctx := errgroup.WithContext(ctx)
|
||||
eg.Go(func() error {
|
||||
code, err := printer.Run(options.Start.CascadeStop, options.Start.ExitCodeFrom, stopFunc)
|
||||
exitCode = code
|
||||
|
@ -88,7 +91,7 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|||
})
|
||||
|
||||
err = s.start(ctx, project.Name, options.Start, printer.HandleEvent)
|
||||
if err != nil {
|
||||
if err != nil && !isTerminated { // Ignore error if the process is terminated
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue