mirror of https://github.com/docker/compose.git
Handle errors and allow to send multiple kills if one failed
Signed-off-by: Jaime Soriano Pastor <jaime.soriano@elastic.co>
This commit is contained in:
parent
5daed33c6a
commit
6a3501f901
|
@ -21,6 +21,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
|
"sync/atomic"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/compose-spec/compose-go/v2/types"
|
"github.com/compose-spec/compose-go/v2/types"
|
||||||
|
@ -29,6 +30,7 @@ import (
|
||||||
"github.com/docker/compose/v2/internal/tracing"
|
"github.com/docker/compose/v2/internal/tracing"
|
||||||
"github.com/docker/compose/v2/pkg/api"
|
"github.com/docker/compose/v2/pkg/api"
|
||||||
"github.com/docker/compose/v2/pkg/progress"
|
"github.com/docker/compose/v2/pkg/progress"
|
||||||
|
"github.com/docker/docker/errdefs"
|
||||||
"github.com/eiannone/keyboard"
|
"github.com/eiannone/keyboard"
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -106,6 +108,9 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// killRunning is used to control that we don't run more than one kill if signals are spammed.
|
||||||
|
var killRunning atomic.Bool
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-doneCh:
|
case <-doneCh:
|
||||||
|
@ -117,19 +122,27 @@ func (s *composeService) Up(ctx context.Context, project *types.Project, options
|
||||||
case <-signalChan:
|
case <-signalChan:
|
||||||
if first {
|
if first {
|
||||||
gracefulTeardown()
|
gracefulTeardown()
|
||||||
} else {
|
break
|
||||||
|
}
|
||||||
|
if !killRunning.CompareAndSwap(false, true) {
|
||||||
|
break
|
||||||
|
}
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
|
defer killRunning.Store(false)
|
||||||
// Intentionally ignore errors, for cases where some
|
// Intentionally ignore errors, for cases where some
|
||||||
// of the containers are already stopped.
|
// of the containers are already stopped.
|
||||||
s.kill(context.Background(), project.Name, api.KillOptions{
|
err := s.kill(context.Background(), project.Name, api.KillOptions{
|
||||||
Services: options.Create.Services,
|
Services: options.Create.Services,
|
||||||
Project: project,
|
Project: project,
|
||||||
All: true,
|
All: true,
|
||||||
})
|
})
|
||||||
return nil
|
// Ignore errors indicating that some of the containers were already stopped or removed.
|
||||||
})
|
if errdefs.IsNotFound(err) || errdefs.IsConflict(err) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
})
|
||||||
case event := <-kEvents:
|
case event := <-kEvents:
|
||||||
formatter.KeyboardManager.HandleKeyEvents(event, ctx, project, options)
|
formatter.KeyboardManager.HandleKeyEvents(event, ctx, project, options)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue