mirror of https://github.com/docker/docs.git
Reguardless of success reset time increment
Reset the time increment if the container's execution time is greater than 10s or else as a container runs and is restarted the time will grow overtime. Signed-off-by: Michael Crosby <michael@docker.com>
This commit is contained in:
parent
972c894931
commit
ebf5d4657d
|
@ -43,6 +43,9 @@ type containerMonitor struct {
|
||||||
// timeIncrement is the amount of time to wait between restarts
|
// timeIncrement is the amount of time to wait between restarts
|
||||||
// this is in milliseconds
|
// this is in milliseconds
|
||||||
timeIncrement int
|
timeIncrement int
|
||||||
|
|
||||||
|
// lastStartTime is the time which the monitor last exec'd the container's process
|
||||||
|
lastStartTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func newContainerMonitor(container *Container, policy runconfig.RestartPolicy) *containerMonitor {
|
func newContainerMonitor(container *Container, policy runconfig.RestartPolicy) *containerMonitor {
|
||||||
|
@ -113,6 +116,8 @@ func (m *containerMonitor) Start() error {
|
||||||
|
|
||||||
m.container.LogEvent("start")
|
m.container.LogEvent("start")
|
||||||
|
|
||||||
|
m.lastStartTime = time.Now()
|
||||||
|
|
||||||
if exitStatus, err = m.container.daemon.Run(m.container, pipes, m.callback); err != nil {
|
if exitStatus, err = m.container.daemon.Run(m.container, pipes, m.callback); err != nil {
|
||||||
utils.Errorf("Error running container: %s", err)
|
utils.Errorf("Error running container: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -154,20 +159,25 @@ func (m *containerMonitor) Start() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// resetMonitor resets the stateful fields on the containerMonitor based on the
|
// resetMonitor resets the stateful fields on the containerMonitor based on the
|
||||||
// previous runs success or failure
|
// previous runs success or failure. Reguardless of success, if the container had
|
||||||
|
// an execution time of more than 10s then reset the timer back to the default
|
||||||
func (m *containerMonitor) resetMonitor(successful bool) {
|
func (m *containerMonitor) resetMonitor(successful bool) {
|
||||||
// the container exited successfully so we need to reset the failure counter
|
executionTime := time.Now().Sub(m.lastStartTime).Seconds()
|
||||||
// and the timeIncrement back to the default values
|
|
||||||
if successful {
|
if executionTime > 10 {
|
||||||
m.failureCount = 0
|
|
||||||
m.timeIncrement = defaultTimeIncrement
|
m.timeIncrement = defaultTimeIncrement
|
||||||
} else {
|
} else {
|
||||||
// otherwise we need to increment the amount of time we wait before restarting
|
// otherwise we need to increment the amount of time we wait before restarting
|
||||||
// the process. We will build up by multiplying the increment by 2
|
// the process. We will build up by multiplying the increment by 2
|
||||||
|
|
||||||
m.failureCount++
|
|
||||||
m.timeIncrement *= 2
|
m.timeIncrement *= 2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// the container exited successfully so we need to reset the failure counter
|
||||||
|
if successful {
|
||||||
|
m.failureCount = 0
|
||||||
|
} else {
|
||||||
|
m.failureCount++
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// waitForNextRestart waits with the default time increment to restart the container unless
|
// waitForNextRestart waits with the default time increment to restart the container unless
|
||||||
|
|
Loading…
Reference in New Issue