Skip to content
Snippets Groups Projects
podman-cleanup 630 B
Newer Older
#!/bin/bash
#
# This script removes unused resources for podman on cluster nodes in the bcf slurm cluster.
# It assumes that the podman run directory is located at /tmp/podman-run-${UID}. It will delete
# unused images, stopped containers, unused volumes and the podman run directory.
#
set -eo pipefail
PODMAN_DIR=/tmp/podman-run-${UID}

if [[ -e $PODMAN_DIR ]]
then
  echo "Podman found on $(hostname)"
  RUNNING_COUNT=$(podman ps --noheading | wc -l)
  podman system prune -a -f
  if [[ $RUNNING_COUNT -gt 0 ]]
  then
    echo "You still have ${RUNNING_COUNT} jobs running on $(hostname)"
  else
    rm -rf $PODMAN_DIR
  fi
fi