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

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