proxmox: reimplement image cleanup

This commit is contained in:
Koushik Dutta
2025-10-12 21:28:00 -07:00
parent 1e825b84bc
commit cab0afaa53

View File

@@ -7,10 +7,25 @@ export DEBIAN_FRONTEND=noninteractive
yes | dpkg --configure -a
apt -y --fix-broken install && apt -y update && apt -y dist-upgrade
function cleanup() {
IS_UP=$(docker compose ps scrypted -a | grep Up)
# Only clean up when scrypted is running to safely free space without risking its image deletion
if [ -z "$IS_UP" ]; then
echo "scrypted is not running, skipping cleanup to preserve its image"
return
fi
echo $(date) > .last_cleanup
echo "scrypted is running, proceeding with cleanup to free space"
docker container prune -f
docker image prune -a -f
}
# force a pull to ensure we have the latest images.
# not using --pull always cause that fails everything on network down
docker compose pull
(sleep 60 && cleanup) &
# do not daemonize, when it exits, systemd will restart it.
# force a recreate as .env may have changed.
# furthermore force recreate gets the container back into a known state