Newer
Older
#!/bin/bash
set -eo pipefail
USER_ID=$(id -u)
PODMAN_DIR=/tmp/podman-run-${USER_ID}
PODMAN="podman --cgroup-manager=cgroupfs"
if [[ -e $PODMAN_DIR ]]
then
echo "Podman found on $(hostname)"
set +e
RUNNING_COUNT=$($PODMAN ps --noheading | wc -l)
RET=$?
set -e
# if podman ps fails, assume that podman is in a corrupted state and reset it
if [[ ! ($RET == 0) ]]
echo "Podman is in a corrupt state on $(hostname). Resetting it."
$PODMAN system migrate
$PODMAN system reset -f
echo "Podman reset on $(hostname)"
fi
if [[ $RUNNING_COUNT -gt 0 || ! ($RET == 0) ]]
then
echo "You still have ${RUNNING_COUNT} jobs running on $(hostname). Podman directory won't be removed."
else
rm -rf $PODMAN_DIR
echo "Podman run-directory removed on $(hostname)"