mirror of https://github.com/docker/compose.git
Merge pull request #1451 from docker/down_sigterm
This commit is contained in:
commit
9f81314124
|
@ -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
|
||||
}()
|
||||
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue