fix: restart service db proxies

This commit is contained in:
Andras Bacsai 2024-03-25 12:35:31 +01:00
parent 8cb6f67a60
commit 61f3b3592f
2 changed files with 52 additions and 20 deletions

View File

@ -8,6 +8,7 @@
use App\Actions\Shared\ComplexStatusCheck; use App\Actions\Shared\ComplexStatusCheck;
use App\Models\ApplicationPreview; use App\Models\ApplicationPreview;
use App\Models\Server; use App\Models\Server;
use App\Models\ServiceDatabase;
use App\Notifications\Container\ContainerRestarted; use App\Notifications\Container\ContainerRestarted;
use App\Notifications\Container\ContainerStopped; use App\Notifications\Container\ContainerStopped;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
@ -149,31 +150,63 @@ public function handle()
} }
} else { } else {
$uuid = data_get($labels, 'com.docker.compose.service'); $uuid = data_get($labels, 'com.docker.compose.service');
$type = data_get($labels, 'coolify.type');
if ($uuid) { if ($uuid) {
$database = $databases->where('uuid', $uuid)->first(); if ($type === 'service') {
if ($database) { $database_id = data_get($labels, 'coolify.service.subId');
$isPublic = data_get($database, 'is_public'); if ($database_id) {
$foundDatabases[] = $database->id; $service_db = ServiceDatabase::where('id', $database_id)->first();
$statusFromDb = $database->status; if ($service_db) {
if ($statusFromDb !== $containerStatus) { $uuid = $service_db->service->uuid;
$database->update(['status' => $containerStatus]); $isPublic = data_get($service_db, 'is_public');
} if ($isPublic) {
if ($isPublic) { $foundTcpProxy = $containers->filter(function ($value, $key) use ($uuid) {
$foundTcpProxy = $containers->filter(function ($value, $key) use ($uuid) { if ($this->server->isSwarm()) {
if ($this->server->isSwarm()) { return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid";
return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid"; } else {
} else { return data_get($value, 'Name') === "/$uuid-proxy";
return data_get($value, 'Name') === "/$uuid-proxy"; }
})->first();
if (!$foundTcpProxy) {
StartDatabaseProxy::run($service_db);
$this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$service_db->service->name}", $this->server));
}
} }
})->first();
if (!$foundTcpProxy) {
StartDatabaseProxy::run($database);
$this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$database->name}", $this->server));
} }
} }
} else { } else {
// Notify user that this container should not be there. $database = $databases->where('uuid', $uuid)->first();
if ($uuid == 'postgresql') {
ray($database);
}
if ($database) {
$isPublic = data_get($database, 'is_public');
$foundDatabases[] = $database->id;
$statusFromDb = $database->status;
if ($statusFromDb !== $containerStatus) {
$database->update(['status' => $containerStatus]);
}
ray($database);
if ($isPublic) {
$foundTcpProxy = $containers->filter(function ($value, $key) use ($uuid) {
if ($this->server->isSwarm()) {
return data_get($value, 'Spec.Name') === "coolify-proxy_$uuid";
} else {
return data_get($value, 'Name') === "/$uuid-proxy";
}
})->first();
if (!$foundTcpProxy) {
ray('asdffff');
StartDatabaseProxy::run($database);
$this->server->team?->notify(new ContainerRestarted("TCP Proxy for {$database->name}", $this->server));
}
}
} else {
// Notify user that this container should not be there.
}
} }
} }
if (data_get($container, 'Name') === '/coolify-db') { if (data_get($container, 'Name') === '/coolify-db') {
$foundDatabases[] = 0; $foundDatabases[] = 0;

View File

@ -37,7 +37,6 @@ public function mount()
public function instantSaveExclude() public function instantSaveExclude()
{ {
$this->submit(); $this->submit();
} }
public function instantSaveLogDrain() public function instantSaveLogDrain()
{ {