Skip to content
Snippets Groups Projects
podman-cleanup 854 B
Newer Older
#!/bin/bash
set -eo pipefail
Lukas Jelonek's avatar
Lukas Jelonek committed
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)"
Lukas Jelonek's avatar
Lukas Jelonek committed
  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) ]]
Lukas Jelonek's avatar
Lukas Jelonek committed
    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."
Lukas Jelonek's avatar
Lukas Jelonek committed
    echo "Podman run-directory removed on $(hostname)"
Lukas Jelonek's avatar
Lukas Jelonek committed
else
  echo "Podman not found on $(hostname)"