Переглянути джерело

Honor the restarting state in Stop

Signed-off-by: Michael Crosby <michael@docker.com>
Michael Crosby 11 роки тому
батько
коміт
c4a00d549d
3 змінених файлів з 18 додано та 10 видалено
  1. 7 0
      daemon/container.go
  2. 4 5
      daemon/monitor.go
  3. 7 5
      daemon/state.go

+ 7 - 0
daemon/container.go

@@ -530,6 +530,13 @@ func (container *Container) KillSig(sig int) error {
 	// after we send the kill signal
 	container.monitor.ExitOnNext()
 
+	// if the container is currently restarting we do not need to send the signal
+	// to the process.  Telling the monitor that it should exit on it's next event
+	// loop is enough
+	if container.State.IsRestarting() {
+		return nil
+	}
+
 	return container.daemon.Kill(container, sig)
 }
 

+ 4 - 5
daemon/monitor.go

@@ -116,16 +116,15 @@ func (m *containerMonitor) Start() error {
 			time.Sleep(time.Duration(m.timeIncrement) * time.Millisecond)
 
 			continue
-		} else {
-			// we still wait to set the state as stopped and ensure that the locks were released
-			m.container.State.SetStopped(exitStatus)
-
-			m.resetContainer()
 		}
 
 		break
 	}
 
+	m.container.State.SetStopped(exitStatus)
+
+	m.resetContainer()
+
 	return err
 }
 

+ 7 - 5
daemon/state.go

@@ -31,14 +31,13 @@ func (s *State) String() string {
 	s.RLock()
 	defer s.RUnlock()
 
-	if s.Restarting {
-		return fmt.Sprintf("Restarting (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt)))
-	}
-
 	if s.Running {
 		if s.Paused {
 			return fmt.Sprintf("Up %s (Paused)", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt)))
 		}
+		if s.Restarting {
+			return fmt.Sprintf("Restarting (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt)))
+		}
 
 		return fmt.Sprintf("Up %s", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt)))
 	}
@@ -148,7 +147,10 @@ func (s *State) SetStopped(exitCode int) {
 func (s *State) SetRestarting(exitCode int) {
 	s.Lock()
 	if s.Running {
-		s.Running = false
+		// we should consider the container running when it is restarting because of
+		// all the checks in docker around rm/stop/etc
+		s.Running = true
+		s.Restarting = true
 		s.Pid = 0
 		s.FinishedAt = time.Now().UTC()
 		s.ExitCode = exitCode