From 337a0ecae9a3cc69b9da2c3ff4971967ae5023a3 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 12 Feb 2021 11:37:33 +0100 Subject: [PATCH] stop as all registered containers exited || cascadestop Signed-off-by: Nicolas De Loof --- cli/cmd/compose/up.go | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/cli/cmd/compose/up.go b/cli/cmd/compose/up.go index 057b2acb84..8dd1a43232 100644 --- a/cli/cmd/compose/up.go +++ b/cli/cmd/compose/up.go @@ -263,26 +263,35 @@ type printer struct { func (p printer) run(ctx context.Context, cascadeStop bool, exitCodeFrom string, consumer compose.LogConsumer, stopFn func() error) (int, error) { //nolint:unparam var aborting bool + var count int for { event := <-p.queue switch event.Type { case compose.ContainerEventAttach: consumer.Register(event.Service, event.Source) + count++ case compose.ContainerEventExit: if !aborting { consumer.Status(event.Service, event.Source, fmt.Sprintf("exited with code %d", event.ExitCode)) } - if cascadeStop && !aborting { - aborting = true - fmt.Println("Aborting on container exit...") - err := stopFn() - if err != nil { - return 0, err + if cascadeStop { + if !aborting { + aborting = true + fmt.Println("Aborting on container exit...") + err := stopFn() + if err != nil { + return 0, err + } + } + if exitCodeFrom == "" || exitCodeFrom == event.Service { + logrus.Error(event.ExitCode) + return event.ExitCode, nil } } - if exitCodeFrom == "" || exitCodeFrom == event.Service { - logrus.Error(event.ExitCode) - return event.ExitCode, nil + count-- + if count == 0 { + // Last container terminated, done + return 0, nil } case compose.ContainerEventLog: if !aborting {