@@ -31,7 +31,7 @@ import (
3131 "github.com/hashicorp/go-multierror"
3232)
3333
34- func (s * composeService ) Up (ctx context.Context , project * types.Project , options api.UpOptions ) error {
34+ func (s * composeService ) Up (ctx context.Context , project * types.Project , options api.UpOptions ) error { //nolint:gocyclo
3535 err := progress .Run (ctx , tracing .SpanWrapFunc ("project/up" , tracing .ProjectOptions (project ), func (ctx context.Context ) error {
3636 err := s .create (ctx , project , options .Create )
3737 if err != nil {
@@ -69,24 +69,31 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
6969 doneCh := make (chan bool )
7070 eg .Go (func () error {
7171 first := true
72+ gracefulTeardown := func () {
73+ printer .Cancel ()
74+ fmt .Fprintln (s .stdinfo (), "Gracefully stopping... (press Ctrl+C again to force)" )
75+ eg .Go (func () error {
76+ err := s .Stop (context .Background (), project .Name , api.StopOptions {
77+ Services : options .Create .Services ,
78+ Project : project ,
79+ })
80+ isTerminated = true
81+ close (doneCh )
82+ return err
83+ })
84+ first = false
85+ }
7286 for {
7387 select {
7488 case <- doneCh :
7589 return nil
90+ case <- ctx .Done ():
91+ if first {
92+ gracefulTeardown ()
93+ }
7694 case <- signalChan :
7795 if first {
78- printer .Cancel ()
79- fmt .Fprintln (s .stdinfo (), "Gracefully stopping... (press Ctrl+C again to force)" )
80- eg .Go (func () error {
81- err := s .Stop (context .Background (), project .Name , api.StopOptions {
82- Services : options .Create .Services ,
83- Project : project ,
84- })
85- isTerminated = true
86- close (doneCh )
87- return err
88- })
89- first = false
96+ gracefulTeardown ()
9097 } else {
9198 eg .Go (func () error {
9299 return s .Kill (context .Background (), project .Name , api.KillOptions {
0 commit comments