From 463a6953261be68de8a26d522afc0999499dfcda Mon Sep 17 00:00:00 2001 From: Simon L Date: Sun, 25 Jun 2023 01:27:44 +0200 Subject: [PATCH 1/2] add low-on-space notification Signed-off-by: Simon L --- Containers/mastercontainer/cron.sh | 3 +++ php/src/Cron/CheckFreeDiskSpace.php | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 php/src/Cron/CheckFreeDiskSpace.php 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..b8fffe27969 --- /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 all docker volumes 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 all docker volumes has less than 5 GB free space. Container updates and backups might not succeed due to that!'); +} From 2b5d3de48e281c10138924015a150fae25604dc8 Mon Sep 17 00:00:00 2001 From: Simon L Date: Mon, 26 Jun 2023 14:48:02 +0200 Subject: [PATCH 2/2] adjust wording Signed-off-by: Simon L Signed-off-by: Simon L. --- php/src/Cron/CheckFreeDiskSpace.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/php/src/Cron/CheckFreeDiskSpace.php b/php/src/Cron/CheckFreeDiskSpace.php index b8fffe27969..b462195ec78 100644 --- a/php/src/Cron/CheckFreeDiskSpace.php +++ b/php/src/Cron/CheckFreeDiskSpace.php @@ -21,6 +21,6 @@ $df = disk_free_space(DataConst::GetDataDirectory()); if ($df !== false && (int)$df < 1024 * 1024 * 1024 * 5) { - error_log("The drive that hosts all docker volumes 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 all docker volumes has less than 5 GB free space. Container updates and backups might not succeed due to that!'); + 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!'); }