diff --git a/Containers/mastercontainer/cron.sh b/Containers/mastercontainer/cron.sh index 384b1604653..60fd4f2c0bc 100644 --- a/Containers/mastercontainer/cron.sh +++ b/Containers/mastercontainer/cron.sh @@ -57,6 +57,9 @@ while true; do # Remove dangling images sudo -u www-data docker image prune --force + # Check for available free space + sudo -u www-data php /var/www/docker-aio/php/src/Cron/CheckFreeDiskSpace.php + # Remove mastercontainer from default bridge network if sudo -u www-data docker inspect nextcloud-aio-mastercontainer --format "{{.NetworkSettings.Networks}}" | grep -q "bridge"; then sudo -u www-data docker network disconnect bridge nextcloud-aio-mastercontainer diff --git a/php/src/Cron/CheckFreeDiskSpace.php b/php/src/Cron/CheckFreeDiskSpace.php new file mode 100644 index 00000000000..b462195ec78 --- /dev/null +++ b/php/src/Cron/CheckFreeDiskSpace.php @@ -0,0 +1,26 @@ +get(\AIO\Docker\DockerActionManager::class); +/** @var \AIO\ContainerDefinitionFetcher $containerDefinitionFetcher */ +$containerDefinitionFetcher = $container->get(\AIO\ContainerDefinitionFetcher::class); + +$id = 'nextcloud-aio-nextcloud'; +$nextcloudContainer = $containerDefinitionFetcher->GetContainerById($id); + +$df = disk_free_space(DataConst::GetDataDirectory()); +if ($df !== false && (int)$df < 1024 * 1024 * 1024 * 5) { + error_log("The drive that hosts the mastercontainer volume has less than 5 GB free space. Container updates and backups might not succeed due to that!"); + $dockerActionManger->sendNotification($nextcloudContainer, 'Low on space!', 'The drive that hosts the mastercontainer volume has less than 5 GB free space. Container updates and backups might not succeed due to that!'); +}