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

Commit 9f81314

Browse files
authored
Merge pull request #1451 from docker/down_sigterm
2 parents 40a24af + a942ef4 commit 9f81314

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

cli/cmd/compose/up.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,21 +274,26 @@ func runCreateStart(ctx context.Context, opts upOptions, services []string) erro
274274
queue: queue,
275275
}
276276

277+
signalChan := make(chan os.Signal, 1)
278+
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
277279
stopFunc := func() error {
278280
ctx := context.Background()
279281
_, err := progress.Run(ctx, func(ctx context.Context) (string, error) {
282+
go func() {
283+
<-signalChan
284+
c.ComposeService().Kill(ctx, project, compose.KillOptions{}) // nolint:errcheck
285+
}()
286+
280287
return "", c.ComposeService().Stop(ctx, project, compose.StopOptions{})
281288
})
282289
return err
283290
}
284-
signalChan := make(chan os.Signal, 1)
285-
signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM)
286291
go func() {
287292
<-signalChan
288293
queue <- compose.ContainerEvent{
289294
Type: compose.UserCancel,
290295
}
291-
fmt.Println("Gracefully stopping...")
296+
fmt.Println("Gracefully stopping... (press Ctrl+C again to force)")
292297
stopFunc() // nolint:errcheck
293298
}()
294299

local/compose/attach.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (s *composeService) attach(ctx context.Context, project *types.Project, lis
8383
s.attachContainer(ctx, container, listener, project) // nolint: errcheck
8484
delete(crashed, event.Container)
8585

86-
s.waitContainer(ctx, container, listener)
86+
s.waitContainer(container, listener)
8787
}
8888
return nil
8989
},

local/compose/start.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ func (s *composeService) Start(ctx context.Context, project *types.Project, opti
5151
for _, c := range containers {
5252
c := c
5353
go func() {
54-
s.waitContainer(ctx, c, options.Attach)
54+
s.waitContainer(c, options.Attach)
5555
}()
5656
}
5757
return nil
5858
}
5959

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

0 commit comments

Comments
 (0)