Skip to content

Commit 2dabbe0

Browse files
Fixed handling of force removal of stuck podman containers in stopping state
1 parent efd87b4 commit 2dabbe0

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

OracleIdentityGovernance/samples/scripts/agentManagement.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,27 @@ else
718718
fi
719719
}
720720

721+
forceRmPodman()
722+
{
723+
# Get the main process for the container.
724+
CONTAINER_ID=$(podman ps -a | grep "$AI" | awk '{print $1}')
725+
if [ -n "${CONTAINER_ID}" ]; then
726+
echo Container ID : "$CONTAINER_ID"
727+
CONTAINER_PROCESS_ID=$(ps -ef | grep -v grep | grep "$CONTAINER_ID" | awk '{print $2}')
728+
echo Container Process ID: ${CONTAINER_PROCESS_ID}
729+
730+
# Kill any processes containing the process ID.
731+
# This kills the child processes too.
732+
kill -9 `ps -ef | grep -v grep | grep ${CONTAINER_PROCESS_ID} | awk '{print $2}'`
733+
734+
# Stop the container, as Podman doesn't notice the processes are dead until you interact with the container.
735+
echo "Removing container. Ignore errors."
736+
podman rm -f "$AI"
737+
else
738+
echo "Container Already Removed"
739+
fi
740+
}
741+
721742
# shellcheck source=/dev/null
722743
stop()
723744
{
@@ -779,6 +800,7 @@ kill()
779800
podman exec "$AI" /bin/bash -c 'agent --config /app/data/conf/config.json ido lcm -i status_check; while [[ "$?" != "2" && "$?" != "255" ]]; do sleep 5s;agent --config /app/data/conf/config.json ido lcm -i status_check; done' >/dev/null
780801
fi
781802
podman rm -f "$AI"
803+
forceRmPodman
782804
fi
783805
}
784806

0 commit comments

Comments
 (0)