fix: proxy container status

This commit is contained in:
Andras Bacsai 2023-09-18 12:08:19 +02:00
parent 9646969107
commit 9a706d55b4

View File

@ -40,7 +40,8 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
return $this->server->uuid; return $this->server->uuid;
} }
private function checkServerConnection() { private function checkServerConnection()
{
$uptime = instant_remote_process(['uptime'], $this->server, false); $uptime = instant_remote_process(['uptime'], $this->server, false);
if (!is_null($uptime)) { if (!is_null($uptime)) {
return true; return true;
@ -66,6 +67,7 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
sleep(5); sleep(5);
} }
$containers = instant_remote_process(["docker container ls -q"], $this->server); $containers = instant_remote_process(["docker container ls -q"], $this->server);
ray($containers);
if (!$containers) { if (!$containers) {
return; return;
} }
@ -74,14 +76,20 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
$applications = $this->server->applications(); $applications = $this->server->applications();
$databases = $this->server->databases(); $databases = $this->server->databases();
$previews = $this->server->previews(); $previews = $this->server->previews();
if ($this->server->isProxyShouldRun()) {
/// Check if proxy is running
$foundProxyContainer = $containers->filter(function ($value, $key) { $foundProxyContainer = $containers->filter(function ($value, $key) {
return data_get($value, 'Name') === '/coolify-proxy'; return data_get($value, 'Name') === '/coolify-proxy';
})->first(); })->first();
if (!$foundProxyContainer) { if (!$foundProxyContainer) {
if ($this->server->isProxyShouldRun()) {
resolve(StartProxy::class)($this->server, false); resolve(StartProxy::class)($this->server, false);
$this->server->team->notify(new ContainerRestarted('coolify-proxy', $this->server)); $this->server->team->notify(new ContainerRestarted('coolify-proxy', $this->server));
} }
} else {
ray($foundProxyContainer);
$this->server->proxy->status = data_get($foundProxyContainer, 'State.Status');
$this->server->save();
} }
$foundApplications = []; $foundApplications = [];
$foundApplicationPreviews = []; $foundApplicationPreviews = [];
@ -132,7 +140,6 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
} }
} }
} }
} }
$notRunningApplications = $applications->pluck('id')->diff($foundApplications); $notRunningApplications = $applications->pluck('id')->diff($foundApplications);
foreach ($notRunningApplications as $applicationId) { foreach ($notRunningApplications as $applicationId) {
@ -253,7 +260,6 @@ class ContainerStatusJob implements ShouldQueue, ShouldBeEncrypted
return Str::startsWith(data_get($value, 'Name'), "/$uuid-pr-{$preview->id}"); return Str::startsWith(data_get($value, 'Name'), "/$uuid-pr-{$preview->id}");
})->first(); })->first();
} }
} }
foreach ($databases as $database) { foreach ($databases as $database) {
$uuid = data_get($database, 'uuid'); $uuid = data_get($database, 'uuid');