|
|
@@ -31,7 +31,7 @@ import (
|
|
|
"github.com/hashicorp/go-multierror"
|
|
|
)
|
|
|
|
|
|
-func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error {
|
|
|
+func (s *composeService) Up(ctx context.Context, project *types.Project, options api.UpOptions) error { //nolint:gocyclo
|
|
|
err := progress.Run(ctx, tracing.SpanWrapFunc("project/up", tracing.ProjectOptions(project), func(ctx context.Context) error {
|
|
|
err := s.create(ctx, project, options.Create)
|
|
|
if err != nil {
|
|
|
@@ -69,24 +69,31 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
|
|
doneCh := make(chan bool)
|
|
|
eg.Go(func() error {
|
|
|
first := true
|
|
|
+ gracefulTeardown := func() {
|
|
|
+ printer.Cancel()
|
|
|
+ fmt.Fprintln(s.stdinfo(), "Gracefully stopping... (press Ctrl+C again to force)")
|
|
|
+ eg.Go(func() error {
|
|
|
+ err := s.Stop(context.Background(), project.Name, api.StopOptions{
|
|
|
+ Services: options.Create.Services,
|
|
|
+ Project: project,
|
|
|
+ })
|
|
|
+ isTerminated = true
|
|
|
+ close(doneCh)
|
|
|
+ return err
|
|
|
+ })
|
|
|
+ first = false
|
|
|
+ }
|
|
|
for {
|
|
|
select {
|
|
|
case <-doneCh:
|
|
|
return nil
|
|
|
+ case <-ctx.Done():
|
|
|
+ if first {
|
|
|
+ gracefulTeardown()
|
|
|
+ }
|
|
|
case <-signalChan:
|
|
|
if first {
|
|
|
- printer.Cancel()
|
|
|
- fmt.Fprintln(s.stdinfo(), "Gracefully stopping... (press Ctrl+C again to force)")
|
|
|
- eg.Go(func() error {
|
|
|
- err := s.Stop(context.Background(), project.Name, api.StopOptions{
|
|
|
- Services: options.Create.Services,
|
|
|
- Project: project,
|
|
|
- })
|
|
|
- isTerminated = true
|
|
|
- close(doneCh)
|
|
|
- return err
|
|
|
- })
|
|
|
- first = false
|
|
|
+ gracefulTeardown()
|
|
|
} else {
|
|
|
eg.Go(func() error {
|
|
|
return s.Kill(context.Background(), project.Name, api.KillOptions{
|