summaryrefslogtreecommitdiff
path: root/libpod/healthcheck_linux.go
diff options
context:
space:
mode:
authorBrent Baude <bbaude@redhat.com>2021-12-16 13:55:08 -0600
committerBrent Baude <bbaude@redhat.com>2021-12-16 14:11:50 -0600
commite88c21366d33dccb25ef292610b9894aa5087260 (patch)
tree0971d140df9f2d14ce0bf30e734f8c93f536193d /libpod/healthcheck_linux.go
parent273da42af237dde44d34d215dfafa33f0b76d9ab (diff)
downloadpodman-e88c21366d33dccb25ef292610b9894aa5087260.tar.gz
podman-e88c21366d33dccb25ef292610b9894aa5087260.tar.bz2
podman-e88c21366d33dccb25ef292610b9894aa5087260.zip
Removed .service file for healthchecks
when a container with healthchecks exits due to stopping or failure, we need the cleanup process to remove both the timer file and the service file. Bz#:2024229 Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/healthcheck_linux.go')
-rw-r--r--libpod/healthcheck_linux.go24
1 files changed, 16 insertions, 8 deletions
diff --git a/libpod/healthcheck_linux.go b/libpod/healthcheck_linux.go
index e08214809..2c19e0a61 100644
--- a/libpod/healthcheck_linux.go
+++ b/libpod/healthcheck_linux.go
@@ -1,6 +1,7 @@
package libpod
import (
+ "context"
"fmt"
"os"
"os/exec"
@@ -59,9 +60,9 @@ func (c *Container) startTimer() error {
return err
}
-// removeTimer removes the systemd timer and unit files
+// removeTransientFiles removes the systemd timer and unit files
// for the container
-func (c *Container) removeTimer() error {
+func (c *Container) removeTransientFiles(ctx context.Context) error {
if c.disableHealthCheckSystemd() {
return nil
}
@@ -71,12 +72,19 @@ func (c *Container) removeTimer() error {
}
defer conn.Close()
timerFile := fmt.Sprintf("%s.timer", c.ID())
- _, err = conn.StopUnit(timerFile, "fail", nil)
-
- // We want to ignore errors where the timer unit has already been removed. The error
- // return is generic so we have to check against the string in the error
- if err != nil && strings.HasSuffix(err.Error(), ".timer not loaded.") {
- return nil
+ serviceFile := fmt.Sprintf("%s.service", c.ID())
+ // We want to ignore errors where the timer unit and/or service unit has already
+ // been removed. The error return is generic so we have to check against the
+ // string in the error
+ if _, err = conn.StopUnitContext(ctx, serviceFile, "fail", nil); err != nil {
+ if !strings.HasSuffix(err.Error(), ".service not loaded.") {
+ return errors.Wrapf(err, "unable to remove service file")
+ }
+ }
+ if _, err = conn.StopUnitContext(ctx, timerFile, "fail", nil); err != nil {
+ if strings.HasSuffix(err.Error(), ".timer not loaded.") {
+ return nil
+ }
}
return err
}