From 79af222c2df979971aa176aa6774dc6900e2afa0 Mon Sep 17 00:00:00 2001 From: szaimen Date: Fri, 11 Mar 2022 22:12:31 +0100 Subject: [PATCH] fix startdomaincheckcontainer logic Signed-off-by: szaimen --- php/src/Controller/DockerController.php | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index 7de6c1dd..5feaf699 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -149,22 +149,32 @@ class DockerController public function StartDomaincheckContainer() : void { # Don't start if domain is already set - if ($this->configurationManager->GetDomain() != '') { + if ($this->configurationManager->GetDomain() !== '' || $this->configurationManager->wasStartButtonClicked()) { return; } $id = 'nextcloud-aio-domaincheck'; - $container = $this->containerDefinitionFetcher->GetContainerById($id); - // don't start if the domaincheck is already running - if ($container->GetIdentifier() === $id && $container->GetRunningState() instanceof RunningState) { - return; - // don't start if apache is already running - } elseif ($container->GetIdentifier() === self::TOP_CONTAINER && $container->GetRunningState() instanceof RunningState) { + $cacheKey = 'domaincheckWasStarted'; + + $domaincheckContainer = $this->containerDefinitionFetcher->GetContainerById($id); + $apacheContainer = $this->containerDefinitionFetcher->GetContainerById(self::TOP_CONTAINER); + // Don't start if apache is already running + if ($apacheContainer->GetRunningState() instanceof RunningState) { return; + // Don't start if domaincheck is already running + } elseif ($domaincheckContainer->GetRunningState() instanceof RunningState) { + $domaincheckWasStarted = apcu_fetch($cacheKey); + // Start domaincheck again when 10 minutes are over by not returning here + if($domaincheckWasStarted !== false && is_string($domaincheckWasStarted)) { + return; + } } $this->PerformRecursiveContainerStart($id); + + // Cache the start for 10 minutes + apcu_add($cacheKey, '1', 600); } private function StopDomaincheckContainer() : void