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

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