From 68ddc72e9b7741c1b564a7f20d7e223ecfa45271 Mon Sep 17 00:00:00 2001 From: szaimen Date: Fri, 4 Mar 2022 15:36:08 +0100 Subject: [PATCH] don't update database container if it failed before Signed-off-by: szaimen --- php/src/Docker/DockerActionManager.php | 41 ++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 3e07994f..455d2999 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -261,11 +261,19 @@ class DockerActionManager public function PullContainer(Container $container) : void { - $url = $this->BuildApiUrl(sprintf('images/create?fromImage=%s', urlencode($this->BuildImageName($container)))); - try { - $this->guzzleClient->post($url); - } catch (RequestException $e) { - throw $e; + $pullcontainer = true; + if ($container->GetIdentifier() === 'nextcloud-aio-database') { + if ($this->GetDatabasecontainerExitCode() > 0) { + $pullcontainer = false; + } + } + if ($pullcontainer) { + $url = $this->BuildApiUrl(sprintf('images/create?fromImage=%s', urlencode($this->BuildImageName($container)))); + try { + $this->guzzleClient->post($url); + } catch (RequestException $e) { + throw $e; + } } } @@ -507,6 +515,29 @@ class DockerActionManager } } + public function GetDatabasecontainerExitCode() : int + { + $containerName = 'nextcloud-aio-database'; + $url = $this->BuildApiUrl(sprintf('containers/%s/json', urlencode($containerName))); + try { + $response = $this->guzzleClient->get($url); + } catch (RequestException $e) { + if ($e->getCode() === 404) { + return -1; + } + throw $e; + } + + $responseBody = json_decode((string)$response->getBody(), true); + + $exitCode = $responseBody['State']['ExitCode']; + if (is_int($exitCode)) { + return $exitCode; + } else { + return -1; + } + } + public function isLoginAllowed() : bool { $id = 'nextcloud-aio-apache'; $apacheContainer = $this->containerDefinitionFetcher->GetContainerById($id);