Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1451 from docker/down_sigterm
Browse files Browse the repository at this point in the history
  • Loading branch information
ndeloof authored Mar 22, 2021
2 parents 40a24af + a942ef4 commit 9f81314
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 8 additions & 3 deletions cli/cmd/compose/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,26 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
queue: queue,
}

signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
stopFunc := func() error {
ctx := context.Background()
_, err := progress.Run(ctx, func(ctx context.Context) (string, error) {
go func() {
<-signalChan
c.ComposeService().Kill(ctx, project, compose.KillOptions{}) // nolint:errcheck
}()

return "", c.ComposeService().Stop(ctx, project, compose.StopOptions{})
})
return err
}
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-signalChan
queue <- compose.ContainerEvent{
Type: compose.UserCancel,
}
fmt.Println("Gracefully stopping...")
fmt.Println("Gracefully stopping... (press Ctrl+C again to force)")
stopFunc() // nolint:errcheck
}()

Expand Down
2 changes: 1 addition & 1 deletion local/compose/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
s.attachContainer(ctx, container, listener, project) // nolint: errcheck
delete(crashed, event.Container)

s.waitContainer(ctx, container, listener)
s.waitContainer(container, listener)
}
return nil
},
Expand Down
6 changes: 3 additions & 3 deletions local/compose/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ func (s *composeService) Start(ctx context.Context, project *types.Project, opti
for _, c := range containers {
c := c
go func() {
s.waitContainer(ctx, c, options.Attach)
s.waitContainer(c, options.Attach)
}()
}
return nil
}

func (s *composeService) waitContainer(ctx context.Context, c moby.Container, listener compose.ContainerEventListener) {
statusC, errC := s.apiClient.ContainerWait(ctx, c.ID, container.WaitConditionNotRunning)
func (s *composeService) waitContainer(c moby.Container, listener compose.ContainerEventListener) {
statusC, errC := s.apiClient.ContainerWait(context.Background(), c.ID, container.WaitConditionNotRunning)
name := getContainerNameWithoutProject(c)
select {
case status := <-statusC:
Expand Down

0 comments on commit 9f81314

Please sign in to comment.