mirror of
https://github.com/containrrr/watchtower.git
synced 2025-12-14 14:10:12 +01:00
Handle errors without halting
If we receive an error while trying to shutdown/startup a particular container we don't want to immediately terminate the current update cycle. Instead we should continue processing the remaining containers and simply log the error.
This commit is contained in:
parent
e21c21ec3b
commit
812fb60805
2 changed files with 10 additions and 7 deletions
|
|
@ -2,6 +2,7 @@ package actions
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math/rand"
|
"math/rand"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/CenturyLinkLabs/watchtower/container"
|
"github.com/CenturyLinkLabs/watchtower/container"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
|
@ -9,6 +10,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
letters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
|
||||||
|
waitTime = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func allContainersFilter(container.Container) bool { return true }
|
func allContainersFilter(container.Container) bool { return true }
|
||||||
|
|
@ -45,8 +47,8 @@ func Update(client container.Client) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if container.Stale {
|
if container.Stale {
|
||||||
if err := client.StopContainer(container, 10); err != nil {
|
if err := client.StopContainer(container, waitTime); err != nil {
|
||||||
return err
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -60,12 +62,13 @@ func Update(client container.Client) error {
|
||||||
// instance so that the new one can adopt the old name.
|
// instance so that the new one can adopt the old name.
|
||||||
if container.IsWatchtower() {
|
if container.IsWatchtower() {
|
||||||
if err := client.RenameContainer(container, randName()); err != nil {
|
if err := client.RenameContainer(container, randName()); err != nil {
|
||||||
return err
|
log.Error(err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := client.StartContainer(container); err != nil {
|
if err := client.StartContainer(container); err != nil {
|
||||||
return err
|
log.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -160,8 +160,8 @@ func (client DockerClient) waitForStop(c Container, waitTime time.Duration) erro
|
||||||
} else if !ci.State.Running {
|
} else if !ci.State.Running {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue