Skip to content

Commit

Permalink
Add Unhealthy state
Browse files Browse the repository at this point in the history
Signed-off-by: Jean-Yves <[email protected]>
  • Loading branch information
docjyJ committed Oct 7, 2024
1 parent 554c546 commit b9ca83a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions php/src/Container/WorkingState.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ enum WorkingState: string {
case Running = 'running';
case Starting = 'starting';
case Stopped = 'stopped';
case Unhealthy = 'unhealthy';
}
12 changes: 7 additions & 5 deletions php/src/Docker/DockerActionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,12 @@ public function GetContainerRunningState(Container $container) : WorkingState

$responseBody = json_decode((string)$response->getBody(), true);

if ($responseBody['State']['Running'] === true) {
return WorkingState::Running;
} else {
if ($responseBody['State']['Running'] !== true) {
return WorkingState::Stopped;
} elseif(array_key_exists('Health', $responseBody['State']) && $responseBody['State']['Health']['Status'] !== 'healthy') {
return WorkingState::Unhealthy;
} else {
return WorkingState::Running;
}
}

Expand Down Expand Up @@ -133,12 +135,12 @@ public function GetContainerStartingState(Container $container) : WorkingState
$connection = @fsockopen($containerName, (int)$internalPort, $errno, $errstr, 0.2);
if ($connection) {
fclose($connection);
return WorkingState::Running;
return $runningState;
} else {
return WorkingState::Starting;
}
} else {
return WorkingState::Running;
return $runningState;
}
}

Expand Down
7 changes: 7 additions & 0 deletions php/templates/containers.twig
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,13 @@
(<a href="{{ container.GetDocumentation() }}">docs</a>)
{% endif %}
</span>
{% elseif container.GetRunningState().value == 'unhealthy' %}
<span class="status running"></span>
<span>{{ container.GetDisplayName() }} (<a href="/api/docker/logs?id={{ container.GetIdentifier() }}" target="_blank" rel="noopener">Unhealthy</a>)
{% if container.GetDocumentation() != '' %}
(<a href="{{ container.GetDocumentation() }}">docs</a>)
{% endif %}
</span>
{% elseif container.GetRunningState().value == 'running' %}
<span class="status success"></span>
<span>{{ container.GetDisplayName() }} (<a href="/api/docker/logs?id={{ container.GetIdentifier() }}" target="_blank" rel="noopener">Running</a>)
Expand Down

0 comments on commit b9ca83a

Please sign in to comment.