Merge pull request #6 from nextcloud/enh/noid/notifications-updatechecker

add sendnotifications and update checker cron
This commit is contained in:
szaimen 2021-11-30 13:52:19 +01:00 committed by GitHub
commit ad788499df
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 77 additions and 1 deletions

View file

@ -213,6 +213,7 @@ RUN set -ex; \
openssl \
gnupg \
dirmngr \
git \
; \
rm -rf /var/lib/apt/lists/*

View file

@ -3,7 +3,7 @@
SUBJECT="$1"
MESSAGE="$2"
if [ "$(php /var/www/html/occ config:app:get notificaations enabled)" = "no" ]; then
if [ "$(php /var/www/html/occ config:app:get notifications enabled)" = "no" ]; then
echo "Cannot send notification as notification app is not enabled."
exit 1
fi

30
php/src/Cron/cron.php Normal file
View file

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
// increase memory limit to 2GB
ini_set('memory_limit', '2048M');
use DI\Container;
require __DIR__ . '/../../vendor/autoload.php';
$container = \AIO\DependencyInjection::GetContainer();
/** @var \AIO\Docker\DockerActionManager $dockerActionManger */
$dockerActionManger = $container->get(\AIO\Docker\DockerActionManager::class);
/** @var \AIO\ContainerDefinitionFetcher $containerDefinitionFetcher */
$containerDefinitionFetcher = $container->get(\AIO\ContainerDefinitionFetcher::class);
$id = 'nextcloud-aio-nextcloud';
$nextcloudContainer = $containerDefinitionFetcher->GetContainerById($id);
$isMastercontainerUpdateAvailable = $dockerActionManger->IsMastercontainerUpdateAvailable();
$isAnyUpdateAvailable = $dockerActionManger->isAnyUpdateAvailable();
if ($isMastercontainerUpdateAvailable === true) {
$dockerActionManger->sendNotification($nextcloudContainer, 'Mastercontainer update available!', 'Please open your management interface to update it.');
}
if ($isAnyUpdateAvailable === true) {
$dockerActionManger->sendNotification($nextcloudContainer, 'Container updates available!', 'Please open your management interface to update them.');
}

View file

@ -367,6 +367,51 @@ class DockerActionManager
}
}
public function sendNotification(Container $container, string $subject, string $message)
{
if ($this->GetContainerStartingState($container) instanceof RunningState) {
$containerName = $container->GetIdentifier();
// schedule the exec
$url = $this->BuildApiUrl(sprintf('/containers/%s/exec', urlencode($containerName)));
$response = json_decode(
$this->guzzleClient->request(
'POST',
$url,
[
'json' => [
'AttachStdout' => true,
'Tty' => true,
'Cmd' => [
'bash',
'/notify.sh',
$subject,
$message
],
],
]
)->getBody()->getContents()
);
// get the id from the response
$id = $response['Id'];
// start the exec
$url = $this->BuildApiUrl(sprintf('/exec/%s/start', $id));
$this->guzzleClient->request(
'POST',
$url,
[
'json' => [
'Detach' => false,
'Tty' => true,
],
]
);
}
}
public function DisconnectContainerFromNetwork(Container $container)
{