Blame SOURCES/bz1718219-podman-2-improve-monitor-action.patch

734564
From 9685e8e6bf2896377a9cf0e07a85de5dd5fcf2df Mon Sep 17 00:00:00 2001
734564
From: Michele Baldessari <michele@acksyn.org>
734564
Date: Wed, 12 Jun 2019 12:00:31 +0200
734564
Subject: [PATCH] Simplify podman_monitor()
734564
734564
Before this change podman_monitor() does two things:
734564
\-> podman_simple_status()
734564
    \-> podman inspect {{.State.Running}}
734564
\-> if podman_simple_status == 0 then monitor_cmd_exec()
734564
    \-> if [ -z "$OCF_RESKEY_monitor_cmd" ]; then # so if OCF_RESKEY_monitor_cmd is empty we just return SUCCESS
734564
          return $rc
734564
        fi
734564
        # if OCF_RESKEY_monitor_cmd is set to something we execute it
734564
        podman exec ${CONTAINER} $OCF_RESKEY_monitor_cmd
734564
734564
Let's actually only rely on podman exec as invoked inside monitor_cmd_exec
734564
when $OCF_RESKEY_monitor_cmd is non empty (which is the default as it is set to "/bin/true").
734564
When there is no monitor_cmd command defined then it makes sense to rely on podman inspect
734564
calls container in podman_simple_status().
734564
734564
Tested as follows:
734564
1) Injected the change on an existing bundle-based cluster
734564
2) Observed that monitoring operations kept working okay
734564
3) Restarted rabbitmq-bundle and galera-bundle successfully
734564
4) Killed a container and we correctly detected the monitor failure
734564
Jun 12 09:52:12 controller-0 pacemaker-controld[25747]: notice: controller-0-haproxy-bundle-podman-1_monitor_60000:230 [ ocf-exit-reason:monitor cmd failed (rc=125), output: cannot exec into container that is not running\n ]
734564
5) Container correctly got restarted after the monitor failure:
734564
   haproxy-bundle-podman-1      (ocf::heartbeat:podman):        Started controller-0
734564
6) Stopped and removed a container and pcmk detected it correctly:
734564
Jun 12 09:55:15 controller-0 podman(haproxy-bundle-podman-1)[841411]: ERROR: monitor cmd failed (rc=125), output: unable to exec into haproxy-bundle-podman-1: no container with name or ID haproxy-bundle-podman-1 found: no such container
734564
Jun 12 09:55:15 controller-0 pacemaker-execd[25744]: notice: haproxy-bundle-podman-1_monitor_60000:841411:stderr [ ocf-exit-reason:monitor cmd failed (rc=125), output: unable to exec into haproxy-bundle-podman-1: no container with name or ID haproxy-bundle-podman-1 found: no such container ]
734564
7) pcmk was able to start the container that was stopped and removed:
734564
Jun 12 09:55:16 controller-0 pacemaker-controld[25747]: notice: Result of start operation for haproxy-bundle-podman-1 on controller-0: 0 (ok)
734564
8) Added 'set -x' to the RA and correctly observed that no 'podman inspect' has been invoked during monitoring operations
734564
734564
Signed-off-by: Michele Baldessari <michele@acksyn.org>
734564
---
734564
 heartbeat/podman | 11 +++--------
734564
 1 file changed, 3 insertions(+), 8 deletions(-)
734564
734564
diff --git a/heartbeat/podman b/heartbeat/podman
734564
index b2b3081f9..a9bd57dea 100755
734564
--- a/heartbeat/podman
734564
+++ b/heartbeat/podman
734564
@@ -255,15 +255,10 @@ podman_simple_status()
734564
 
734564
 podman_monitor()
734564
 {
734564
-	local rc=0
734564
-
734564
-	podman_simple_status
734564
-	rc=$?
734564
-
734564
-	if [ $rc -ne 0 ]; then
734564
-		return $rc
734564
+	if [ -z "$OCF_RESKEY_monitor_cmd" ]; then
734564
+		podman_simple_status
734564
+		return $?
734564
 	fi
734564
-
734564
 	monitor_cmd_exec
734564
 }
734564