From dc209adb843b4503434a3625e19e35fa8743c53d Mon Sep 17 00:00:00 2001 From: Jean-Yves <7360784+docjyJ@users.noreply.github.com> Date: Mon, 7 Oct 2024 13:20:49 +0200 Subject: [PATCH] Update php/src/Container/WorkingState.php Co-authored-by: Simon L. Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com> --- php/src/Container/Container.php | 6 ++-- .../{WorkingState.php => ContainerState.php} | 2 +- php/src/Controller/DockerController.php | 8 ++--- php/src/Docker/DockerActionManager.php | 34 +++++++++---------- 4 files changed, 25 insertions(+), 25 deletions(-) rename php/src/Container/{WorkingState.php => ContainerState.php} (89%) diff --git a/php/src/Container/Container.php b/php/src/Container/Container.php index e207136266e..0f9e9de575d 100644 --- a/php/src/Container/Container.php +++ b/php/src/Container/Container.php @@ -112,11 +112,11 @@ public function GetVolumes() : ContainerVolumes { return $this->volumes; } - public function GetRunningState() : WorkingState { + public function GetRunningState() : ContainerState { return $this->dockerActionManager->GetContainerRunningState($this); } - public function GetRestartingState() : WorkingState { + public function GetRestartingState() : ContainerState { return $this->dockerActionManager->GetContainerRestartingState($this); } @@ -124,7 +124,7 @@ public function GetUpdateState() : VersionState { return $this->dockerActionManager->GetContainerUpdateState($this); } - public function GetStartingState() : WorkingState { + public function GetStartingState() : ContainerState { return $this->dockerActionManager->GetContainerStartingState($this); } diff --git a/php/src/Container/WorkingState.php b/php/src/Container/ContainerState.php similarity index 89% rename from php/src/Container/WorkingState.php rename to php/src/Container/ContainerState.php index 3b4a24ccfc2..f6481027fdd 100644 --- a/php/src/Container/WorkingState.php +++ b/php/src/Container/ContainerState.php @@ -2,7 +2,7 @@ namespace AIO\Container; -enum WorkingState: string { +enum ContainerState: string { case ImageDoesNotExist = 'image_does_not_exist'; case NotRestarting = 'not_restarting'; case Restarting = 'restarting'; diff --git a/php/src/Controller/DockerController.php b/php/src/Controller/DockerController.php index db499b102cf..840985f8691 100644 --- a/php/src/Controller/DockerController.php +++ b/php/src/Controller/DockerController.php @@ -2,7 +2,7 @@ namespace AIO\Controller; -use AIO\Container\WorkingState; +use AIO\Container\ContainerState; use AIO\ContainerDefinitionFetcher; use AIO\Docker\DockerActionManager; use Psr\Http\Message\ResponseInterface as Response; @@ -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() === WorkingState::Running) { + if ($container->GetRunningState() === ContainerState::Running) { error_log('Not starting ' . $id . ' because it was already started.'); return; } @@ -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() === WorkingState::Running) { + if ($apacheContainer->GetRunningState() === ContainerState::Running) { return; // Don't start if domaincheck is already running - } elseif ($domaincheckContainer->GetRunningState() === WorkingState::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)) { diff --git a/php/src/Docker/DockerActionManager.php b/php/src/Docker/DockerActionManager.php index 89257df5b6d..12a641e0869 100644 --- a/php/src/Docker/DockerActionManager.php +++ b/php/src/Docker/DockerActionManager.php @@ -4,7 +4,7 @@ use AIO\Container\Container; use AIO\Container\VersionState; -use AIO\Container\WorkingState; +use AIO\Container\ContainerState; use AIO\Data\ConfigurationManager; use GuzzleHttp\Client; use GuzzleHttp\Exception\RequestException; @@ -35,14 +35,14 @@ private function BuildImageName(Container $container) : string { return $container->GetContainerName() . ':' . $tag; } - public function GetContainerRunningState(Container $container) : WorkingState + public function GetContainerRunningState(Container $container) : ContainerState { $url = $this->BuildApiUrl(sprintf('containers/%s/json', urlencode($container->GetIdentifier()))); try { $response = $this->guzzleClient->get($url); } catch (RequestException $e) { if ($e->getCode() === 404) { - return WorkingState::ImageDoesNotExist; + return ContainerState::ImageDoesNotExist; } throw $e; } @@ -50,20 +50,20 @@ public function GetContainerRunningState(Container $container) : WorkingState $responseBody = json_decode((string)$response->getBody(), true); if ($responseBody['State']['Running'] === true) { - return WorkingState::Running; + return ContainerState::Running; } else { - return WorkingState::Stopped; + return ContainerState::Stopped; } } - public function GetContainerRestartingState(Container $container) : WorkingState + public function GetContainerRestartingState(Container $container) : ContainerState { $url = $this->BuildApiUrl(sprintf('containers/%s/json', urlencode($container->GetIdentifier()))); try { $response = $this->guzzleClient->get($url); } catch (RequestException $e) { if ($e->getCode() === 404) { - return WorkingState::ImageDoesNotExist; + return ContainerState::ImageDoesNotExist; } throw $e; } @@ -71,9 +71,9 @@ public function GetContainerRestartingState(Container $container) : WorkingState $responseBody = json_decode((string)$response->getBody(), true); if ($responseBody['State']['Restarting'] === true) { - return WorkingState::Restarting; + return ContainerState::Restarting; } else { - return WorkingState::NotRestarting; + return ContainerState::NotRestarting; } } @@ -101,10 +101,10 @@ public function GetContainerUpdateState(Container $container) : VersionState return VersionState::Different; } - public function GetContainerStartingState(Container $container) : WorkingState + public function GetContainerStartingState(Container $container) : ContainerState { $runningState = $this->GetContainerRunningState($container); - if ($runningState === WorkingState::Stopped || $runningState === WorkingState::ImageDoesNotExist) { + if ($runningState === ContainerState::Stopped || $runningState === ContainerState::ImageDoesNotExist) { return $runningState; } @@ -120,12 +120,12 @@ public function GetContainerStartingState(Container $container) : WorkingState $connection = @fsockopen($containerName, (int)$internalPort, $errno, $errstr, 0.2); if ($connection) { fclose($connection); - return WorkingState::Running; + return ContainerState::Running; } else { - return WorkingState::Starting; + return ContainerState::Starting; } } else { - return WorkingState::Running; + return ContainerState::Running; } } @@ -780,7 +780,7 @@ public function IsMastercontainerUpdateAvailable() : bool public function sendNotification(Container $container, string $subject, string $message, string $file = '/notify.sh') : void { - if ($this->GetContainerStartingState($container) === WorkingState::Running) { + if ($this->GetContainerStartingState($container) === ContainerState::Running) { $containerName = $container->GetIdentifier(); @@ -964,7 +964,7 @@ public function GetDatabasecontainerExitCode() : int public function isLoginAllowed() : bool { $id = 'nextcloud-aio-apache'; $apacheContainer = $this->containerDefinitionFetcher->GetContainerById($id); - if ($this->GetContainerStartingState($apacheContainer) === WorkingState::Running) { + if ($this->GetContainerStartingState($apacheContainer) === ContainerState::Running) { return false; } return true; @@ -973,7 +973,7 @@ public function isLoginAllowed() : bool { public function isBackupContainerRunning() : bool { $id = 'nextcloud-aio-borgbackup'; $backupContainer = $this->containerDefinitionFetcher->GetContainerById($id); - if ($this->GetContainerRunningState($backupContainer) === WorkingState::Running) { + if ($this->GetContainerRunningState($backupContainer) === ContainerState::Running) { return true; } return false;