From c4a00d549d0b895bb990491cbdf58aabe2891842 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Mon, 11 Aug 2014 11:35:18 -0700 Subject: [PATCH] Honor the restarting state in Stop Signed-off-by: Michael Crosby --- daemon/container.go | 7 +++++++ daemon/monitor.go | 9 ++++----- daemon/state.go | 12 +++++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/daemon/container.go b/daemon/container.go index 681852a17d..e0da3c144a 100644 --- a/daemon/container.go +++ b/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) } diff --git a/daemon/monitor.go b/daemon/monitor.go index b733531dff..6c6c7b76db 100644 --- a/daemon/monitor.go +++ b/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 } diff --git a/daemon/state.go b/daemon/state.go index 00597d699a..61b65f7d4e 100644 --- a/daemon/state.go +++ b/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