Update based on comments from the code review

Signed-off-by: Michael Crosby <michael@docker.com>
This commit is contained in:
Michael Crosby 2014-08-13 14:56:35 -07:00
parent 2ec1b697c1
commit 73ced63680
2 changed files with 19 additions and 17 deletions

View file

@ -24,7 +24,7 @@ type containerMonitor struct {
// container is the container being monitored
container *Container
// restartPolicy is the being applied to the container monitor
// restartPolicy is the current policy being applied to the container monitor
restartPolicy runconfig.RestartPolicy
// failureCount is the number of times the container has failed to
@ -35,8 +35,7 @@ type containerMonitor struct {
// either because docker or the user asked for the container to be stopped
shouldStop bool
// startSignal signals with the initial process has launched after calling Start
// on the monitor
// startSignal is a channel that is closes after the container initially starts
startSignal chan struct{}
// stopChan is used to signal to the monitor whenever there is a wait for the
@ -196,7 +195,7 @@ func (m *containerMonitor) resetMonitor(successful bool) {
}
// waitForNextRestart waits with the default time increment to restart the container unless
// a user or docker asks to container to be stopped
// a user or docker asks for the container to be stopped
func (m *containerMonitor) waitForNextRestart() {
select {
case <-time.After(time.Duration(m.timeIncrement) * time.Millisecond):
@ -245,8 +244,11 @@ func (m *containerMonitor) callback(command *execdriver.Command) {
m.container.State.SetRunning(command.Pid())
// signal that the process has started
close(m.startSignal)
if m.startSignal != nil {
// signal that the process has started
close(m.startSignal)
m.startSignal = nil
}
if err := m.container.ToDisk(); err != nil {
utils.Debugf("%s", err)

View file

@ -123,6 +123,7 @@ func (s *State) SetRunning(pid int) {
s.Lock()
s.Running = true
s.Paused = false
s.Restarting = false
s.ExitCode = 0
s.Pid = pid
s.StartedAt = time.Now().UTC()
@ -134,6 +135,7 @@ func (s *State) SetRunning(pid int) {
func (s *State) SetStopped(exitCode int) {
s.Lock()
s.Running = false
s.Restarting = false
s.Pid = 0
s.FinishedAt = time.Now().UTC()
s.ExitCode = exitCode
@ -146,17 +148,15 @@ func (s *State) SetStopped(exitCode int) {
// in the middle of a stop and being restarted again
func (s *State) SetRestarting(exitCode int) {
s.Lock()
if s.Running {
// 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
close(s.waitChan) // fire waiters for stop
s.waitChan = make(chan struct{})
}
// 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
close(s.waitChan) // fire waiters for stop
s.waitChan = make(chan struct{})
s.Unlock()
}