@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "errors"
2222 "fmt"
23+ "github.com/sirupsen/logrus"
2324 "os"
2425 "path/filepath"
2526
@@ -152,14 +153,15 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
152153
153154 ctx , cancel := context .WithCancel (ctx )
154155 listener := make (chan compose.ContainerExited )
156+ exitCode := make (chan int )
155157 go func () {
156158 var aborting bool
157159 for {
158- <- listener
160+ exit := <- listener
159161 if opts .cascadeStop && ! aborting {
160162 aborting = true
161- fmt .Println ("Aborting on container exit..." )
162163 cancel ()
164+ exitCode <- exit .Status
163165 }
164166 }
165167 }()
@@ -170,15 +172,29 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
170172 })
171173
172174 if errors .Is (ctx .Err (), context .Canceled ) {
173- fmt .Println ("Gracefully stopping..." )
174- ctx = context .Background ()
175- _ , err = progress .Run (ctx , func (ctx context.Context ) (string , error ) {
176- return "" , c .ComposeService ().Stop (ctx , project )
177- })
175+ select {
176+ case exit := <- exitCode :
177+ fmt .Println ("Aborting on container exit..." )
178+ err = stop (c , project )
179+ logrus .Error (exit )
180+ // os.Exit(exit)
181+ default :
182+ // cancelled by user
183+ fmt .Println ("Gracefully stopping..." )
184+ err = stop (c , project )
185+ }
178186 }
179187 return err
180188}
181189
190+ func stop (c * client.Client , project * types.Project ) error {
191+ ctx := context .Background ()
192+ _ , err := progress .Run (ctx , func (ctx context.Context ) (string , error ) {
193+ return "" , c .ComposeService ().Stop (ctx , project )
194+ })
195+ return err
196+ }
197+
182198func setup (ctx context.Context , opts composeOptions , services []string ) (* client.Client , * types.Project , error ) {
183199 c , err := client .NewWithDefaultLocalBackend (ctx )
184200 if err != nil {
0 commit comments