mirror of
https://github.com/nextcloud/all-in-one.git
synced 2025-12-19 22:16:49 +00:00
Update php/src/Container/WorkingState.php
Co-authored-by: Simon L. <szaimen@e.mail.de> Signed-off-by: Jean-Yves <7360784+docjyJ@users.noreply.github.com>
This commit is contained in:
parent
edeb5ca40a
commit
dc209adb84
4 changed files with 25 additions and 25 deletions
|
|
@ -112,11 +112,11 @@ readonly class Container {
|
||||||
return $this->volumes;
|
return $this->volumes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetRunningState() : WorkingState {
|
public function GetRunningState() : ContainerState {
|
||||||
return $this->dockerActionManager->GetContainerRunningState($this);
|
return $this->dockerActionManager->GetContainerRunningState($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetRestartingState() : WorkingState {
|
public function GetRestartingState() : ContainerState {
|
||||||
return $this->dockerActionManager->GetContainerRestartingState($this);
|
return $this->dockerActionManager->GetContainerRestartingState($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ readonly class Container {
|
||||||
return $this->dockerActionManager->GetContainerUpdateState($this);
|
return $this->dockerActionManager->GetContainerUpdateState($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetStartingState() : WorkingState {
|
public function GetStartingState() : ContainerState {
|
||||||
return $this->dockerActionManager->GetContainerStartingState($this);
|
return $this->dockerActionManager->GetContainerStartingState($this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace AIO\Container;
|
namespace AIO\Container;
|
||||||
|
|
||||||
enum WorkingState: string {
|
enum ContainerState: string {
|
||||||
case ImageDoesNotExist = 'image_does_not_exist';
|
case ImageDoesNotExist = 'image_does_not_exist';
|
||||||
case NotRestarting = 'not_restarting';
|
case NotRestarting = 'not_restarting';
|
||||||
case Restarting = 'restarting';
|
case Restarting = 'restarting';
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace AIO\Controller;
|
namespace AIO\Controller;
|
||||||
|
|
||||||
use AIO\Container\WorkingState;
|
use AIO\Container\ContainerState;
|
||||||
use AIO\ContainerDefinitionFetcher;
|
use AIO\ContainerDefinitionFetcher;
|
||||||
use AIO\Docker\DockerActionManager;
|
use AIO\Docker\DockerActionManager;
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
|
|
@ -28,7 +28,7 @@ readonly class DockerController {
|
||||||
|
|
||||||
// Don't start if container is already running
|
// Don't start if container is already running
|
||||||
// This is expected to happen if a container is defined in depends_on of multiple containers
|
// 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.');
|
error_log('Not starting ' . $id . ' because it was already started.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -254,10 +254,10 @@ readonly class DockerController {
|
||||||
$domaincheckContainer = $this->containerDefinitionFetcher->GetContainerById($id);
|
$domaincheckContainer = $this->containerDefinitionFetcher->GetContainerById($id);
|
||||||
$apacheContainer = $this->containerDefinitionFetcher->GetContainerById(self::TOP_CONTAINER);
|
$apacheContainer = $this->containerDefinitionFetcher->GetContainerById(self::TOP_CONTAINER);
|
||||||
// Don't start if apache is already running
|
// Don't start if apache is already running
|
||||||
if ($apacheContainer->GetRunningState() === WorkingState::Running) {
|
if ($apacheContainer->GetRunningState() === ContainerState::Running) {
|
||||||
return;
|
return;
|
||||||
// Don't start if domaincheck is already running
|
// Don't start if domaincheck is already running
|
||||||
} elseif ($domaincheckContainer->GetRunningState() === WorkingState::Running) {
|
} elseif ($domaincheckContainer->GetRunningState() === ContainerState::Running) {
|
||||||
$domaincheckWasStarted = apcu_fetch($cacheKey);
|
$domaincheckWasStarted = apcu_fetch($cacheKey);
|
||||||
// Start domaincheck again when 10 minutes are over by not returning here
|
// Start domaincheck again when 10 minutes are over by not returning here
|
||||||
if($domaincheckWasStarted !== false && is_string($domaincheckWasStarted)) {
|
if($domaincheckWasStarted !== false && is_string($domaincheckWasStarted)) {
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ namespace AIO\Docker;
|
||||||
|
|
||||||
use AIO\Container\Container;
|
use AIO\Container\Container;
|
||||||
use AIO\Container\VersionState;
|
use AIO\Container\VersionState;
|
||||||
use AIO\Container\WorkingState;
|
use AIO\Container\ContainerState;
|
||||||
use AIO\Data\ConfigurationManager;
|
use AIO\Data\ConfigurationManager;
|
||||||
use GuzzleHttp\Client;
|
use GuzzleHttp\Client;
|
||||||
use GuzzleHttp\Exception\RequestException;
|
use GuzzleHttp\Exception\RequestException;
|
||||||
|
|
@ -35,14 +35,14 @@ readonly class DockerActionManager {
|
||||||
return $container->GetContainerName() . ':' . $tag;
|
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())));
|
$url = $this->BuildApiUrl(sprintf('containers/%s/json', urlencode($container->GetIdentifier())));
|
||||||
try {
|
try {
|
||||||
$response = $this->guzzleClient->get($url);
|
$response = $this->guzzleClient->get($url);
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
if ($e->getCode() === 404) {
|
if ($e->getCode() === 404) {
|
||||||
return WorkingState::ImageDoesNotExist;
|
return ContainerState::ImageDoesNotExist;
|
||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
@ -50,20 +50,20 @@ readonly class DockerActionManager {
|
||||||
$responseBody = json_decode((string)$response->getBody(), true);
|
$responseBody = json_decode((string)$response->getBody(), true);
|
||||||
|
|
||||||
if ($responseBody['State']['Running'] === true) {
|
if ($responseBody['State']['Running'] === true) {
|
||||||
return WorkingState::Running;
|
return ContainerState::Running;
|
||||||
} else {
|
} 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())));
|
$url = $this->BuildApiUrl(sprintf('containers/%s/json', urlencode($container->GetIdentifier())));
|
||||||
try {
|
try {
|
||||||
$response = $this->guzzleClient->get($url);
|
$response = $this->guzzleClient->get($url);
|
||||||
} catch (RequestException $e) {
|
} catch (RequestException $e) {
|
||||||
if ($e->getCode() === 404) {
|
if ($e->getCode() === 404) {
|
||||||
return WorkingState::ImageDoesNotExist;
|
return ContainerState::ImageDoesNotExist;
|
||||||
}
|
}
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
@ -71,9 +71,9 @@ readonly class DockerActionManager {
|
||||||
$responseBody = json_decode((string)$response->getBody(), true);
|
$responseBody = json_decode((string)$response->getBody(), true);
|
||||||
|
|
||||||
if ($responseBody['State']['Restarting'] === true) {
|
if ($responseBody['State']['Restarting'] === true) {
|
||||||
return WorkingState::Restarting;
|
return ContainerState::Restarting;
|
||||||
} else {
|
} else {
|
||||||
return WorkingState::NotRestarting;
|
return ContainerState::NotRestarting;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,10 +101,10 @@ readonly class DockerActionManager {
|
||||||
return VersionState::Different;
|
return VersionState::Different;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function GetContainerStartingState(Container $container) : WorkingState
|
public function GetContainerStartingState(Container $container) : ContainerState
|
||||||
{
|
{
|
||||||
$runningState = $this->GetContainerRunningState($container);
|
$runningState = $this->GetContainerRunningState($container);
|
||||||
if ($runningState === WorkingState::Stopped || $runningState === WorkingState::ImageDoesNotExist) {
|
if ($runningState === ContainerState::Stopped || $runningState === ContainerState::ImageDoesNotExist) {
|
||||||
return $runningState;
|
return $runningState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,12 +120,12 @@ readonly class DockerActionManager {
|
||||||
$connection = @fsockopen($containerName, (int)$internalPort, $errno, $errstr, 0.2);
|
$connection = @fsockopen($containerName, (int)$internalPort, $errno, $errstr, 0.2);
|
||||||
if ($connection) {
|
if ($connection) {
|
||||||
fclose($connection);
|
fclose($connection);
|
||||||
return WorkingState::Running;
|
return ContainerState::Running;
|
||||||
} else {
|
} else {
|
||||||
return WorkingState::Starting;
|
return ContainerState::Starting;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return WorkingState::Running;
|
return ContainerState::Running;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -780,7 +780,7 @@ readonly class DockerActionManager {
|
||||||
|
|
||||||
public function sendNotification(Container $container, string $subject, string $message, string $file = '/notify.sh') : void
|
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();
|
$containerName = $container->GetIdentifier();
|
||||||
|
|
||||||
|
|
@ -964,7 +964,7 @@ readonly class DockerActionManager {
|
||||||
public function isLoginAllowed() : bool {
|
public function isLoginAllowed() : bool {
|
||||||
$id = 'nextcloud-aio-apache';
|
$id = 'nextcloud-aio-apache';
|
||||||
$apacheContainer = $this->containerDefinitionFetcher->GetContainerById($id);
|
$apacheContainer = $this->containerDefinitionFetcher->GetContainerById($id);
|
||||||
if ($this->GetContainerStartingState($apacheContainer) === WorkingState::Running) {
|
if ($this->GetContainerStartingState($apacheContainer) === ContainerState::Running) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -973,7 +973,7 @@ readonly class DockerActionManager {
|
||||||
public function isBackupContainerRunning() : bool {
|
public function isBackupContainerRunning() : bool {
|
||||||
$id = 'nextcloud-aio-borgbackup';
|
$id = 'nextcloud-aio-borgbackup';
|
||||||
$backupContainer = $this->containerDefinitionFetcher->GetContainerById($id);
|
$backupContainer = $this->containerDefinitionFetcher->GetContainerById($id);
|
||||||
if ($this->GetContainerRunningState($backupContainer) === WorkingState::Running) {
|
if ($this->GetContainerRunningState($backupContainer) === ContainerState::Running) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue