mirror of
https://github.com/containers/podman.git
synced 2025-10-17 03:04:21 +08:00
Merge pull request #26515 from dashea/dshea-3.2.3-healthcheckbackports
[v3.2.3-rhel] Backports for health check files
This commit is contained in:
@ -19,7 +19,7 @@ die_unknown() {
|
|||||||
die "Unknown/unsupported \$$var_name '$var_value'"
|
die "Unknown/unsupported \$$var_name '$var_value'"
|
||||||
}
|
}
|
||||||
|
|
||||||
_EOL=20250531
|
_EOL=20270922
|
||||||
if [[ $(date +%Y%m%d) -ge $_EOL ]]; then
|
if [[ $(date +%Y%m%d) -ge $_EOL ]]; then
|
||||||
die "As of $_EOL this branch is probably
|
die "As of $_EOL this branch is probably
|
||||||
no longer supported in RHEL 8.4.z, please
|
no longer supported in RHEL 8.4.z, please
|
||||||
|
@ -1765,7 +1765,7 @@ func (c *Container) cleanupStorage() error {
|
|||||||
return cleanupErr
|
return cleanupErr
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unmount the a container and free its resources
|
// Unmount the container and free its resources
|
||||||
func (c *Container) cleanup(ctx context.Context) error {
|
func (c *Container) cleanup(ctx context.Context) error {
|
||||||
var lastError error
|
var lastError error
|
||||||
|
|
||||||
@ -1773,8 +1773,8 @@ func (c *Container) cleanup(ctx context.Context) error {
|
|||||||
|
|
||||||
// Remove healthcheck unit/timer file if it execs
|
// Remove healthcheck unit/timer file if it execs
|
||||||
if c.config.HealthCheckConfig != nil {
|
if c.config.HealthCheckConfig != nil {
|
||||||
if err := c.removeTimer(); err != nil {
|
if err := c.removeTransientFiles(ctx); err != nil {
|
||||||
logrus.Errorf("Error removing timer for container %s healthcheck: %v", c.ID(), err)
|
logrus.Errorf("Removing timer for container %s healthcheck: %v", c.ID(), err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
@ -59,9 +60,9 @@ func (c *Container) startTimer() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// removeTimer removes the systemd timer and unit files
|
// removeTransientFiles removes the systemd timer and unit files
|
||||||
// for the container
|
// for the container
|
||||||
func (c *Container) removeTimer() error {
|
func (c *Container) removeTransientFiles(ctx context.Context) error {
|
||||||
if c.disableHealthCheckSystemd() {
|
if c.disableHealthCheckSystemd() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -71,12 +72,29 @@ func (c *Container) removeTimer() error {
|
|||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
timerFile := fmt.Sprintf("%s.timer", c.ID())
|
timerFile := fmt.Sprintf("%s.timer", c.ID())
|
||||||
_, err = conn.StopUnit(timerFile, "fail", nil)
|
serviceFile := fmt.Sprintf("%s.service", c.ID())
|
||||||
|
|
||||||
// We want to ignore errors where the timer unit has already been removed. The error
|
// If the service has failed (the healthcheck has failed), then
|
||||||
// return is generic so we have to check against the string in the error
|
// the .service file is not removed on stopping the unit file. If
|
||||||
if err != nil && strings.HasSuffix(err.Error(), ".timer not loaded.") {
|
// we check the properties of the service, it will automatically
|
||||||
return nil
|
// reset the state. But checking the state takes msecs vs usecs to
|
||||||
|
// blindly call reset.
|
||||||
|
if err := conn.ResetFailedUnitContext(ctx, serviceFile); err != nil {
|
||||||
|
logrus.Debugf("failed to reset unit file: %q", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
. "github.com/containers/podman/v3/test/utils"
|
. "github.com/containers/podman/v3/test/utils"
|
||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
|
. "github.com/onsi/gomega/gexec"
|
||||||
)
|
)
|
||||||
|
|
||||||
var _ = Describe("Podman healthcheck run", func() {
|
var _ = Describe("Podman healthcheck run", func() {
|
||||||
@ -203,4 +204,20 @@ var _ = Describe("Podman healthcheck run", func() {
|
|||||||
inspect = podmanTest.InspectContainer("hc")
|
inspect = podmanTest.InspectContainer("hc")
|
||||||
Expect(inspect[0].State.Healthcheck.Status).To(Equal("healthy"))
|
Expect(inspect[0].State.Healthcheck.Status).To(Equal("healthy"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("stopping and then starting a container with healthcheck cmd", func() {
|
||||||
|
session := podmanTest.Podman([]string{"run", "-dt", "--name", "hc", "--health-cmd", "[\"ls\", \"/foo\"]", ALPINE, "top"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session).Should(Exit(0))
|
||||||
|
|
||||||
|
stop := podmanTest.Podman([]string{"stop", "-t0", "hc"})
|
||||||
|
stop.WaitWithDefaultTimeout()
|
||||||
|
Expect(stop).Should(Exit(0))
|
||||||
|
|
||||||
|
startAgain := podmanTest.Podman([]string{"start", "hc"})
|
||||||
|
startAgain.WaitWithDefaultTimeout()
|
||||||
|
Expect(startAgain).Should(Exit(0))
|
||||||
|
Expect(startAgain.OutputToString()).To(Equal("hc"))
|
||||||
|
Expect(startAgain.ErrorToString()).To(Equal(""))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user