Pre-update lifecycle hook (#793)

* Make watchtower skip update if pre-update lifecycle hook exits with a non-zero exit code
#649

* Make watchtower skip update if pre-update lifecycle hook exits with a non-zero exit code
#649

* Make watchtower skip update if pre-update lifecycle hook exits with a non-zero exit code
#649

* Make watchtower skip update if pre-update lifecycle hook exits with a non-zero exit code
#649

* Make watchtower skip update if pre-update lifecycle hook exits with a non-zero exit code #649

* Make watchtower skip update if pre-update lifecycle hook exits with a non-zero exit code #649

* Make watchtower skip update if pre-update lifecycle hook exits with a non-zero exit code #649

* Prevent starting new container if old one is not stopped because of lifecycle hook.

* Add null check for c.containerInfo.State in IsRunning

* Fixed that the container would not start

* Added test for preupdate

* EX_TEMPFAIL -> ExTempFail

* Added missing fuction ouput names

* Skip preupdate when container is restarting.
This commit is contained in:
yrien30 2021-06-24 00:36:33 +02:00 committed by GitHub
parent dc12a1ac7f
commit 145fe6dbcb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 281 additions and 39 deletions

View file

@ -37,7 +37,8 @@ func ExecutePreCheckCommand(client container.Client, container container.Contain
}
log.Debug("Executing pre-check command.")
if err := client.ExecuteCommand(container.ID(), command, 1); err != nil {
_,err := client.ExecuteCommand(container.ID(), command, 1);
if err != nil {
log.Error(err)
}
}
@ -51,18 +52,24 @@ func ExecutePostCheckCommand(client container.Client, container container.Contai
}
log.Debug("Executing post-check command.")
if err := client.ExecuteCommand(container.ID(), command, 1); err != nil {
_,err := client.ExecuteCommand(container.ID(), command, 1);
if err != nil {
log.Error(err)
}
}
// ExecutePreUpdateCommand tries to run the pre-update lifecycle hook for a single container.
func ExecutePreUpdateCommand(client container.Client, container container.Container) error {
func ExecutePreUpdateCommand(client container.Client, container container.Container) (SkipUpdate bool,err error) {
timeout := container.PreUpdateTimeout()
command := container.GetLifecyclePreUpdateCommand()
if len(command) == 0 {
log.Debug("No pre-update command supplied. Skipping")
return nil
return false,nil
}
if !container.IsRunning() || container.IsRestarting() {
log.Debug("Container is not running. Skipping pre-update command.")
return false,nil
}
log.Debug("Executing pre-update command.")
@ -84,7 +91,9 @@ func ExecutePostUpdateCommand(client container.Client, newContainerID string) {
}
log.Debug("Executing post-update command.")
if err := client.ExecuteCommand(newContainerID, command, 1); err != nil {
_,err = client.ExecuteCommand(newContainerID, command, 1);
if err != nil {
log.Error(err)
}
}