mirror of https://github.com/docker/docs.git
Merge pull request #13277 from runcom/restartpolicy-methods
RestartPolicy methods instead of strings checking
This commit is contained in:
commit
3b69ca5b97
|
@ -122,7 +122,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
|
||||||
fmt.Fprintf(cli.out, "%s\n", createResponse.ID)
|
fmt.Fprintf(cli.out, "%s\n", createResponse.ID)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
if *flAutoRemove && (hostConfig.RestartPolicy.Name == "always" || hostConfig.RestartPolicy.Name == "on-failure") {
|
if *flAutoRemove && (hostConfig.RestartPolicy.IsAlways() || hostConfig.RestartPolicy.IsOnFailure()) {
|
||||||
return ErrConflictRestartPolicyAndAutoRemove
|
return ErrConflictRestartPolicyAndAutoRemove
|
||||||
}
|
}
|
||||||
// We need to instantiate the chan because the select needs it. It can
|
// We need to instantiate the chan because the select needs it. It can
|
||||||
|
|
|
@ -325,8 +325,8 @@ func (daemon *Daemon) restore() error {
|
||||||
logrus.Debug("Restarting containers...")
|
logrus.Debug("Restarting containers...")
|
||||||
|
|
||||||
for _, container := range registeredContainers {
|
for _, container := range registeredContainers {
|
||||||
if container.hostConfig.RestartPolicy.Name == "always" ||
|
if container.hostConfig.RestartPolicy.IsAlways() ||
|
||||||
(container.hostConfig.RestartPolicy.Name == "on-failure" && container.ExitCode != 0) {
|
(container.hostConfig.RestartPolicy.IsOnFailure() && container.ExitCode != 0) {
|
||||||
logrus.Debugf("Starting container %s", container.ID)
|
logrus.Debugf("Starting container %s", container.ID)
|
||||||
|
|
||||||
if err := container.Start(); err != nil {
|
if err := container.Start(); err != nil {
|
||||||
|
|
|
@ -223,10 +223,10 @@ func (m *containerMonitor) shouldRestart(exitCode int) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
switch m.restartPolicy.Name {
|
switch {
|
||||||
case "always":
|
case m.restartPolicy.IsAlways():
|
||||||
return true
|
return true
|
||||||
case "on-failure":
|
case m.restartPolicy.IsOnFailure():
|
||||||
// the default value of 0 for MaximumRetryCount means that we will not enforce a maximum count
|
// the default value of 0 for MaximumRetryCount means that we will not enforce a maximum count
|
||||||
if max := m.restartPolicy.MaximumRetryCount; max != 0 && m.failureCount > max {
|
if max := m.restartPolicy.MaximumRetryCount; max != 0 && m.failureCount > max {
|
||||||
logrus.Debugf("stopping restart of container %s because maximum failure could of %d has been reached",
|
logrus.Debugf("stopping restart of container %s because maximum failure could of %d has been reached",
|
||||||
|
|
|
@ -129,6 +129,18 @@ type RestartPolicy struct {
|
||||||
MaximumRetryCount int
|
MaximumRetryCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rp *RestartPolicy) IsNone() bool {
|
||||||
|
return rp.Name == "no"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rp *RestartPolicy) IsAlways() bool {
|
||||||
|
return rp.Name == "always"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rp *RestartPolicy) IsOnFailure() bool {
|
||||||
|
return rp.Name == "on-failure"
|
||||||
|
}
|
||||||
|
|
||||||
type LogConfig struct {
|
type LogConfig struct {
|
||||||
Type string
|
Type string
|
||||||
Config map[string]string
|
Config map[string]string
|
||||||
|
|
Loading…
Reference in New Issue