Skip to content

Commit

Permalink
Merge pull request #313 from nextcloud/enh/noid/database-safeguard
Browse files Browse the repository at this point in the history
don't update database container if it failed before
  • Loading branch information
szaimen committed Mar 8, 2022
2 parents 8836a88 + 68ddc72 commit 0168b29
Showing 1 changed file with 36 additions and 5 deletions.
41 changes: 36 additions & 5 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,19 @@ public function CreateContainer(Container $container) : void {

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;
}
}
}

Expand Down Expand Up @@ -507,6 +515,29 @@ public function GetBackupcontainerExitCode() : int
}
}

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);
Expand Down

0 comments on commit 0168b29

Please sign in to comment.