Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AIO-interface: add Unhealthy container state #5307

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions php/src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AIO\Data\ConfigurationManager;
use AIO\Docker\DockerActionManager;
use AIO\ContainerDefinitionFetcher;
use GuzzleHttp\Exception\GuzzleException;

readonly class Container {
public function __construct(
Expand Down Expand Up @@ -112,20 +113,13 @@ public function GetVolumes() : ContainerVolumes {
return $this->volumes;
}

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

public function GetRestartingState() : ContainerState {
return $this->dockerActionManager->GetContainerRestartingState($this);
}

public function GetUpdateState() : VersionState {
return $this->dockerActionManager->GetContainerUpdateState($this);
}

public function GetStartingState() : ContainerState {
return $this->dockerActionManager->GetContainerStartingState($this);
public function GetUpdateState() : UpdateState {
return $this->dockerActionManager->GetUpdateState($this);
}

/**
Expand Down
38 changes: 31 additions & 7 deletions php/src/Container/ContainerState.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,35 @@

namespace AIO\Container;

enum ContainerState: string {
case ImageDoesNotExist = 'image_does_not_exist';
case NotRestarting = 'not_restarting';
case Restarting = 'restarting';
case Running = 'running';
docjyJ marked this conversation as resolved.
Show resolved Hide resolved
case Starting = 'starting';
case Stopped = 'stopped';
enum ContainerState {
case DoesNotExist;
case Restarting;
case Healthy;
case Starting;
case Stopped;
case Unhealthy;

public function isStopped(): bool {
return $this == self::Stopped;
}

public function isStarting(): bool {
return $this == self::Starting;
}

public function isRestarting(): bool {
return $this == self::Restarting;
}

public function isHealthy(): bool {
return $this == self::Healthy;
}

public function isUnhealthy(): bool {
return $this == self::Unhealthy;
}

public function isRunning(): bool {
return $this->isHealthy() || $this->isUnhealthy() || $this->isStarting() || $this->isRestarting();
}
Comment on lines +17 to +35
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Running state corresponds to the old GetRunningContainerState state.
Maybe there is another clearer state. Healthy means that the container is running without any problem detected by the AIO.

}
12 changes: 12 additions & 0 deletions php/src/Container/UpdateState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace AIO\Container;

enum UpdateState {
case Outdated;
case Latest;

public function isUpdatableAvailable(): bool {
return $this == self::Outdated;
}
}
8 changes: 0 additions & 8 deletions php/src/Container/VersionState.php

This file was deleted.

9 changes: 6 additions & 3 deletions php/src/Controller/DockerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AIO\Container\ContainerState;
use AIO\ContainerDefinitionFetcher;
use AIO\Docker\DockerActionManager;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use AIO\Data\ConfigurationManager;
Expand All @@ -19,6 +20,7 @@ public function __construct(
) {
}

/** @throws GuzzleException */
private function PerformRecursiveContainerStart(string $id, bool $pullImage = true) : void {
$container = $this->containerDefinitionFetcher->GetContainerById($id);

Expand All @@ -28,7 +30,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() === ContainerState::Running) {
if ($container->GetContainerState()->isRunning()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

container->GetRunningState does not include Starting and Restarting

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid it being hard to understand I went through the isSomething function

error_log('Not starting ' . $id . ' because it was already started.');
return;
}
Expand Down Expand Up @@ -240,6 +242,7 @@ public function stopTopContainer() : void {
$this->PerformRecursiveContainerStop($id);
}

/** @throws GuzzleException */
public function StartDomaincheckContainer() : void
{
# Don't start if domain is already set
Expand All @@ -254,10 +257,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() === ContainerState::Running) {
if ($apacheContainer->GetContainerState()->isRunning()) {
return;
// Don't start if domaincheck is already running
} elseif ($domaincheckContainer->GetRunningState() === ContainerState::Running) {
} elseif ($domaincheckContainer->GetContainerState()->isRunning()) {
$domaincheckWasStarted = apcu_fetch($cacheKey);
// Start domaincheck again when 10 minutes are over by not returning here
if($domaincheckWasStarted !== false && is_string($domaincheckWasStarted)) {
Expand Down
Loading