Sfoglia il codice sorgente

Merge pull request #1451 from docker/down_sigterm

Nicolas De loof 4 anni fa
parent
commit
9f81314124
3 ha cambiato i file con 12 aggiunte e 7 eliminazioni
  1. 8 3
      cli/cmd/compose/up.go
  2. 1 1
      local/compose/attach.go
  3. 3 3
      local/compose/start.go

+ 8 - 3
cli/cmd/compose/up.go

@@ -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
 	}()
 

+ 1 - 1
local/compose/attach.go

@@ -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
 			},

+ 3 - 3
local/compose/start.go

@@ -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: