mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-19 22:16:49 +00:00
daily-backup: implement a dedicated imagepull before stopping containers which should reduce the downtime
Signed-off-by: Simon L. <szaimen@e.mail.de>
This commit is contained in:
parent
c0a3e206c9
commit
b4e4e73616
4 changed files with 69 additions and 21 deletions
|
|
@ -64,6 +64,12 @@ if [ "$AUTOMATIC_UPDATES" = 1 ]; then
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Update container images to reduce downtime later on
|
||||||
|
if [ "$AUTOMATIC_UPDATES" = 1 ]; then
|
||||||
|
echo "Updating container images..."
|
||||||
|
sudo -u www-data php /var/www/docker-aio/php/src/Cron/PullContainerImages.php
|
||||||
|
fi
|
||||||
|
|
||||||
# Stop containers if required
|
# Stop containers if required
|
||||||
# shellcheck disable=SC2235
|
# shellcheck disable=SC2235
|
||||||
if [ "$CHECK_BACKUP" != 1 ] && ([ "$DAILY_BACKUP" != 1 ] || [ "$STOP_CONTAINERS" = 1 ]); then
|
if [ "$CHECK_BACKUP" != 1 ] && ([ "$DAILY_BACKUP" != 1 ] || [ "$STOP_CONTAINERS" = 1 ]); then
|
||||||
|
|
|
||||||
|
|
@ -34,33 +34,32 @@ readonly class DockerController {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Skip database image pull if the last shutdown was not clean
|
|
||||||
if ($id === 'nextcloud-aio-database') {
|
|
||||||
if ($this->dockerActionManager->GetDatabasecontainerExitCode() > 0) {
|
|
||||||
$pullImage = false;
|
|
||||||
error_log('Not pulling the latest database image because the container was not correctly shut down.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if registry is reachable in order to make sure that we do not try to pull an image if it is down
|
|
||||||
// and try to mitigate issues that are arising due to that
|
|
||||||
if ($pullImage) {
|
|
||||||
if (!$this->dockerActionManager->isRegistryReachable($container)) {
|
|
||||||
$pullImage = false;
|
|
||||||
error_log('Not pulling the ' . $container->GetContainerName() . ' image for the ' . $container->GetIdentifier() . ' container because the registry does not seem to be reachable.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->dockerActionManager->DeleteContainer($container);
|
$this->dockerActionManager->DeleteContainer($container);
|
||||||
$this->dockerActionManager->CreateVolumes($container);
|
$this->dockerActionManager->CreateVolumes($container);
|
||||||
if ($pullImage) {
|
$this->dockerActionManager->PullImage($container, $pullImage);
|
||||||
$this->dockerActionManager->PullImage($container);
|
|
||||||
}
|
|
||||||
$this->dockerActionManager->CreateContainer($container);
|
$this->dockerActionManager->CreateContainer($container);
|
||||||
$this->dockerActionManager->StartContainer($container);
|
$this->dockerActionManager->StartContainer($container);
|
||||||
$this->dockerActionManager->ConnectContainerToNetwork($container);
|
$this->dockerActionManager->ConnectContainerToNetwork($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function PerformRecursiveImagePull(string $id) : void {
|
||||||
|
$container = $this->containerDefinitionFetcher->GetContainerById($id);
|
||||||
|
|
||||||
|
// Pull all dependencies first and then itself
|
||||||
|
foreach($container->GetDependsOn() as $dependency) {
|
||||||
|
$this->PerformRecursiveImagePull($dependency);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->dockerActionManager->PullImage($container, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function PullAllContainerImages(): void {
|
||||||
|
|
||||||
|
$id = self::TOP_CONTAINER;
|
||||||
|
|
||||||
|
$this->PerformRecursiveImagePull($id);
|
||||||
|
}
|
||||||
|
|
||||||
public function GetLogs(Request $request, Response $response, array $args) : Response
|
public function GetLogs(Request $request, Response $response, array $args) : Response
|
||||||
{
|
{
|
||||||
$requestParams = $request->getQueryParams();
|
$requestParams = $request->getQueryParams();
|
||||||
|
|
|
||||||
20
php/src/Cron/PullContainerImages.php
Normal file
20
php/src/Cron/PullContainerImages.php
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
// increase memory limit to 2GB
|
||||||
|
ini_set('memory_limit', '2048M');
|
||||||
|
|
||||||
|
// Log whole log messages
|
||||||
|
ini_set('log_errors_max_len', '0');
|
||||||
|
|
||||||
|
use DI\Container;
|
||||||
|
|
||||||
|
require __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
|
||||||
|
$container = \AIO\DependencyInjection::GetContainer();
|
||||||
|
|
||||||
|
/** @var \AIO\Controller\DockerController $dockerController */
|
||||||
|
$dockerController = $container->get(\AIO\Controller\DockerController::class);
|
||||||
|
|
||||||
|
// Pull all containers
|
||||||
|
$dockerController->PullAllContainerImages();
|
||||||
|
|
@ -450,7 +450,30 @@ readonly class DockerActionManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function PullImage(Container $container): void {
|
public function PullImage(Container $container, bool $pullImage = true): void {
|
||||||
|
|
||||||
|
// Skip database image pull if the last shutdown was not clean
|
||||||
|
if ($container->GetIdentifier() === 'nextcloud-aio-database') {
|
||||||
|
if ($this->GetDatabasecontainerExitCode() > 0) {
|
||||||
|
$pullImage = false;
|
||||||
|
error_log('Not pulling the latest database image because the container was not correctly shut down.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if registry is reachable in order to make sure that we do not try to pull an image if it is down
|
||||||
|
// and try to mitigate issues that are arising due to that
|
||||||
|
if ($pullImage) {
|
||||||
|
if (!$this->isRegistryReachable($container)) {
|
||||||
|
$pullImage = false;
|
||||||
|
error_log('Not pulling the ' . $container->GetContainerName() . ' image for the ' . $container->GetIdentifier() . ' container because the registry does not seem to be reachable.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do not continue if $pullImage is false
|
||||||
|
if (!$pullImage) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
$imageName = $this->BuildImageName($container);
|
$imageName = $this->BuildImageName($container);
|
||||||
$encodedImageName = urlencode($imageName);
|
$encodedImageName = urlencode($imageName);
|
||||||
$url = $this->BuildApiUrl(sprintf('images/create?fromImage=%s', $encodedImageName));
|
$url = $this->BuildApiUrl(sprintf('images/create?fromImage=%s', $encodedImageName));
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue