mirror of
https://github.com/nextcloud/all-in-one.git
synced 2024-09-20 23:06:10 +08:00
Merge pull request #6 from nextcloud/enh/noid/notifications-updatechecker
add sendnotifications and update checker cron
This commit is contained in:
commit
ad788499df
|
@ -213,6 +213,7 @@ RUN set -ex; \
|
|||
openssl \
|
||||
gnupg \
|
||||
dirmngr \
|
||||
git \
|
||||
; \
|
||||
rm -rf /var/lib/apt/lists/*
|
||||
|
||||
|
|
|
@ -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
30
php/src/Cron/cron.php
Normal 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.');
|
||||
}
|
|
@ -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)
|
||||
{
|
||||
|
||||
|
|
Loading…
Reference in a new issue