From 83ae27ef76a5e01a430f45f0ecbefb8c145e99c4 Mon Sep 17 00:00:00 2001 From: szaimen Date: Tue, 15 Mar 2022 12:45:31 +0100 Subject: [PATCH] allow to check for restarting state Signed-off-by: szaimen --- php/src/Container/Container.php | 4 ++++ .../Container/State/NotRestartingState.php | 6 +++++ php/src/Container/State/RestartingState.php | 6 +++++ php/src/Docker/DockerActionManager.php | 23 +++++++++++++++++++ php/templates/containers.twig | 20 +++++++++++++--- 5 files changed, 56 insertions(+), 3 deletions(-) create mode 100644 php/src/Container/State/NotRestartingState.php create mode 100644 php/src/Container/State/RestartingState.php diff --git a/php/src/Container/Container.php b/php/src/Container/Container.php index 1119a4ba..c1330da3 100644 --- a/php/src/Container/Container.php +++ b/php/src/Container/Container.php @@ -91,6 +91,10 @@ class Container { return $this->dockerActionManager->GetContainerRunningState($this); } + public function GetRestartingState() : IContainerState { + return $this->dockerActionManager->GetContainerRestartingState($this); + } + public function GetUpdateState() : IContainerState { return $this->dockerActionManager->GetContainerUpdateState($this); } diff --git a/php/src/Container/State/NotRestartingState.php b/php/src/Container/State/NotRestartingState.php new file mode 100644 index 00000000..b035377c --- /dev/null +++ b/php/src/Container/State/NotRestartingState.php @@ -0,0 +1,6 @@ +BuildApiUrl(sprintf('containers/%s/json', urlencode($container->GetIdentifier()))); + try { + $response = $this->guzzleClient->get($url); + } catch (RequestException $e) { + if ($e->getCode() === 404) { + return new ImageDoesNotExistState(); + } + throw $e; + } + + $responseBody = json_decode((string)$response->getBody(), true); + + if ($responseBody['State']['Restarting'] === true) { + return new RestartingState(); + } else { + return new NotRestartingState(); + } + } + public function GetContainerUpdateState(Container $container) : IContainerState { $tag = $this->GetCurrentChannel(); diff --git a/php/templates/containers.twig b/php/templates/containers.twig index 6209266e..6d727afa 100644 --- a/php/templates/containers.twig +++ b/php/templates/containers.twig @@ -20,6 +20,7 @@ This is beta software and not production ready.

{% set isAnyRunning = false %} + {% set isAnyRestarting = false %} {% set isWatchtowerRunning = false %} {% set isBackupContainerRunning = false %} {% set isRestoreRunning = false %} @@ -30,6 +31,9 @@ {% if class(container.GetRunningState()) == 'AIO\\Container\\State\\RunningState' and container.GetIdentifier() != 'nextcloud-aio-domaincheck' and container.GetIdentifier() != 'nextcloud-aio-borgbackup' and container.GetIdentifier() != 'nextcloud-aio-watchtower' %} {% set isAnyRunning = true %} {% endif %} + {% if ( container.GetIdentifier() starts with 'nextcloud-aio-redis' or container.GetIdentifier() starts with 'nextcloud-aio-database' or container.GetIdentifier() starts with 'nextcloud-aio-nextcloud' or container.GetIdentifier() starts with 'nextcloud-aio-apache' ) and class(container.GetRestartingState()) == 'AIO\\Container\\State\\RestartingState' %} + {% set isAnyRestarting = true %} + {% endif %} {% if container.GetIdentifier() == 'nextcloud-aio-watchtower' and class(container.GetRunningState()) == 'AIO\\Container\\State\\RunningState' %} {% set isWatchtowerRunning = true %} {% endif %} @@ -81,8 +85,18 @@ Initial Nextcloud password: {{ nextcloud_password }}

Open your Nextcloud ↗
{% else %} - Containers are currently starting.

- Reload ↻
+ {% if isAnyRestarting == false %} + Containers are currently starting.

+ Reload ↻

+ {% else %} + It seems like at least one container is currently restarting which means it is not able to start correctly.

+ To break out this endless loop, you can stop the containers below and investigate the issue by having a look at the container logs before starting them again.

+
+ + + +
+ {% endif %} {% endif %} {% endif %} @@ -110,7 +124,7 @@ {% if has_update_available == true %} {% if is_mastercontainer_update_available == false %} - ⚠ Container updates are available. Click on `Stop Containers` and `Start Containers` to update them. You should consider creating a backup first.

+ ⚠ Container updates are available. Click on 'Stop Containers' and 'Start Containers' to update them. You should consider creating a backup first.

{% endif %} {% else %} {% if is_mastercontainer_update_available == false %}