Blame SOURCES/bz1839721-podman-force-rm-container-if-rm-fails.patch

5fdbe4
From 5a732511db2c49ff6afe0a20e738b565a35273ae Mon Sep 17 00:00:00 2001
5fdbe4
From: Damien Ciabrini <dciabrin@redhat.com>
5fdbe4
Date: Fri, 29 May 2020 11:57:29 +0200
5fdbe4
Subject: [PATCH] podman: make sure to remove containers with lingering exec
5fdbe4
 sessions
5fdbe4
5fdbe4
It may happen that some "podman exec" commands don't finish
5fdbe4
cleanly and leave lingering "Exec sessions" in the container's
5fdbe4
state. In that case, a "podman rm" command will always fail.
5fdbe4
5fdbe4
To overcome the podman bug, issue a "podman rm -f" command when
5fdbe4
we detect a container is stopped but still has some lingering
5fdbe4
"Exec sessions" associated with it.
5fdbe4
5fdbe4
Related-Bug: rhbz#1839721
5fdbe4
---
5fdbe4
 heartbeat/podman | 16 ++++++++++++++++
5fdbe4
 1 file changed, 16 insertions(+)
5fdbe4
5fdbe4
diff --git a/heartbeat/podman b/heartbeat/podman
5fdbe4
index f77d988fc..e2f6e981b 100755
5fdbe4
--- a/heartbeat/podman
5fdbe4
+++ b/heartbeat/podman
5fdbe4
@@ -232,6 +232,9 @@ container_exists()
5fdbe4
 
5fdbe4
 remove_container()
5fdbe4
 {
5fdbe4
+	local rc
5fdbe4
+	local execids
5fdbe4
+
5fdbe4
 	if ocf_is_true "$OCF_RESKEY_reuse"; then
5fdbe4
 		# never remove the container if we have reuse enabled.
5fdbe4
 		return 0
5fdbe4
@@ -244,6 +247,19 @@ remove_container()
5fdbe4
 	fi
5fdbe4
 	ocf_log notice "Cleaning up inactive container, ${CONTAINER}."
5fdbe4
 	ocf_run podman rm $CONTAINER
5fdbe4
+	rc=$?
5fdbe4
+	if [ $rc -ne 0 ]; then
5fdbe4
+		# due to a podman bug (rhbz#1841485), sometimes a stopped
5fdbe4
+		# container can still be associated with Exec sessions, in
5fdbe4
+		# which case the "podman rm" has to be forced
5fdbe4
+		execids=$(podman inspect $CONTAINER --format '{{len .ExecIDs}}')
5fdbe4
+		if [ "$execids" -ne "0" ]; then
5fdbe4
+			ocf_log warn "Inactive container ${CONTAINER} has lingering exec sessions. Force-remove it."
5fdbe4
+			ocf_run podman rm -f $CONTAINER
5fdbe4
+			rc=$?
5fdbe4
+		fi
5fdbe4
+	fi
5fdbe4
+	return $rc
5fdbe4
 }
5fdbe4
 
5fdbe4
 podman_simple_status()