Skip to content

Commit

Permalink
rollback
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Yves <[email protected]>
  • Loading branch information
docjyJ committed Oct 10, 2024
1 parent ea84e2a commit 41031cb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion php/src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function GetVolumes() : ContainerVolumes {
}

/** @throws GuzzleException */
public function GetRunningState() : RunningState {
public function GetRunningState() : ContainerState {
return $this->dockerActionManager->GetContainerRunningState($this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AIO\Container;

enum RunningState: string {
enum ContainerState: string {
case DoesNotExist = 'does_not_exist';
case Restarting = 'restarting';
case Running = 'running';
Expand Down
8 changes: 4 additions & 4 deletions php/src/Controller/DockerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace AIO\Controller;

use AIO\Container\RunningState;
use AIO\Container\ContainerState;
use AIO\ContainerDefinitionFetcher;
use AIO\Docker\DockerActionManager;
use Psr\Http\Message\ResponseInterface as Response;
Expand All @@ -28,7 +28,7 @@ private function PerformRecursiveContainerStart(string $id, bool $pullImage = tr

// Don't start if container is already running
// This is expected to happen if a container is defined in depends_on of multiple containers
if ($container->GetRunningState() === RunningState::Running) {
if ($container->GetRunningState() === ContainerState::Running) {
error_log('Not starting ' . $id . ' because it was already started.');
return;
}
Expand Down Expand Up @@ -254,10 +254,10 @@ public function StartDomaincheckContainer() : void
$domaincheckContainer = $this->containerDefinitionFetcher->GetContainerById($id);
$apacheContainer = $this->containerDefinitionFetcher->GetContainerById(self::TOP_CONTAINER);
// Don't start if apache is already running
if ($apacheContainer->GetRunningState() === RunningState::Running) {
if ($apacheContainer->GetRunningState() === ContainerState::Running) {
return;
// Don't start if domaincheck is already running
} elseif ($domaincheckContainer->GetRunningState() === RunningState::Running) {
} elseif ($domaincheckContainer->GetRunningState() === ContainerState::Running) {
$domaincheckWasStarted = apcu_fetch($cacheKey);
// Start domaincheck again when 10 minutes are over by not returning here
if($domaincheckWasStarted !== false && is_string($domaincheckWasStarted)) {
Expand Down
28 changes: 14 additions & 14 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use AIO\Container\Container;
use AIO\Container\UpdateState;
use AIO\Container\RunningState;
use AIO\Container\ContainerState;
use AIO\Data\ConfigurationManager;
use AssertionError;
use GuzzleHttp\Client;
Expand Down Expand Up @@ -38,13 +38,13 @@ private function BuildImageName(Container $container) : string {
}

/** @throws GuzzleException */
public function GetContainerRunningState(Container $container): RunningState {
public function GetContainerRunningState(Container $container): ContainerState {
$url = $this->BuildApiUrl(sprintf('containers/%s/json', urlencode($container->GetIdentifier())));
try {
$response = $this->guzzleClient->get($url);
} catch (GuzzleException $e) {
if ($e->getCode() === 404) {
return RunningState::DoesNotExist;
return ContainerState::DoesNotExist;
}
throw $e;
}
Expand All @@ -54,18 +54,18 @@ public function GetContainerRunningState(Container $container): RunningState {
assert(is_array($body['State']));

$state = match ($body['State']['Status']) {
'running' => RunningState::Running,
'created' => RunningState::Starting,
'restarting' => RunningState::Restarting,
'paused', 'removing', 'exited', 'dead' => RunningState::Stopped,
'running' => ContainerState::Running,
'created' => ContainerState::Starting,
'restarting' => ContainerState::Restarting,
'paused', 'removing', 'exited', 'dead' => ContainerState::Stopped,
default => throw new AssertionError()
};

if ($state === RunningState::Running && is_array($body['State']['Health'])) {
if ($state === ContainerState::Running && is_array($body['State']['Health'])) {
return match ($body['State']['Health']['Status']) {
'starting' => RunningState::Starting,
'unhealthy' => RunningState::Unhealthy,
default => RunningState::Running,
'starting' => ContainerState::Starting,
'unhealthy' => ContainerState::Unhealthy,
default => ContainerState::Running,
};
} else {
return $state;
Expand Down Expand Up @@ -744,7 +744,7 @@ public function IsMastercontainerUpdateAvailable() : bool
}

public function sendNotification(Container $container, string $subject, string $message, string $file = '/notify.sh'): void {
if ($this->GetContainerRunningState($container) === RunningState::Running) {
if ($this->GetContainerRunningState($container) === ContainerState::Running) {

$containerName = $container->GetIdentifier();

Expand Down Expand Up @@ -928,7 +928,7 @@ public function GetDatabasecontainerExitCode() : int
public function isLoginAllowed(): bool {
$id = 'nextcloud-aio-apache';
$apacheContainer = $this->containerDefinitionFetcher->GetContainerById($id);
if ($this->GetContainerRunningState($apacheContainer) === RunningState::Running) {
if ($this->GetContainerRunningState($apacheContainer) === ContainerState::Running) {
return false;
}
return true;
Expand All @@ -937,7 +937,7 @@ public function isLoginAllowed(): bool {
public function isBackupContainerRunning(): bool {
$id = 'nextcloud-aio-borgbackup';
$backupContainer = $this->containerDefinitionFetcher->GetContainerById($id);
if ($this->GetContainerRunningState($backupContainer) === RunningState::Running) {
if ($this->GetContainerRunningState($backupContainer) === ContainerState::Running) {
return true;
}
return false;
Expand Down

0 comments on commit 41031cb

Please sign in to comment.