diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 734063b2e..1f7006aaa 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -72,13 +72,13 @@ private function check_resources($schedule) $containerServers = $servers->where('settings.is_swarm_worker', false)->where('settings.is_build_server', false); } foreach ($containerServers as $server) { - $schedule->job(new ContainerStatusJob($server))->everyTwoMinutes()->onOneServer(); + $schedule->job(new ContainerStatusJob($server))->everyMinute()->onOneServer(); if ($server->isLogDrainEnabled()) { - $schedule->job(new CheckLogDrainContainerJob($server))->everyTwoMinutes()->onOneServer(); + $schedule->job(new CheckLogDrainContainerJob($server))->everyMinute()->onOneServer(); } } foreach ($servers as $server) { - $schedule->job(new ServerStatusJob($server))->everyTwoMinutes()->onOneServer(); + $schedule->job(new ServerStatusJob($server))->everyMinute()->onOneServer(); } } private function instance_auto_update($schedule) diff --git a/app/Jobs/ServerStatusJob.php b/app/Jobs/ServerStatusJob.php index 31683d097..d91961bcb 100644 --- a/app/Jobs/ServerStatusJob.php +++ b/app/Jobs/ServerStatusJob.php @@ -38,11 +38,12 @@ public function uniqueId(): int public function handle() { if (!$this->server->isServerReady($this->tries)) { - throw new \RuntimeException('Server is not ready.'); + return "Server is not ready yet."; }; try { if ($this->server->isFunctional()) { $this->cleanup(notify: false); + $this->removeCoolifyYaml(); } } catch (\Throwable $e) { send_internal_notification('ServerStatusJob failed with: ' . $e->getMessage()); @@ -50,6 +51,16 @@ public function handle() return handleError($e); } } + private function removeCoolifyYaml() + { + // This will remote the coolify.yaml file from the server as it is not needed on cloud servers + if (isCloud() && $this->server->id !== 0) { + $file = $this->server->proxyPath() . "/dynamic/coolify.yaml"; + return instant_remote_process([ + "rm -f $file", + ], $this->server, false); + } + } public function cleanup(bool $notify = false): void { $this->disk_usage = $this->server->getDiskUsage(); diff --git a/app/Livewire/Server/Form.php b/app/Livewire/Server/Form.php index 14a2809c7..c1dcd34ce 100644 --- a/app/Livewire/Server/Form.php +++ b/app/Livewire/Server/Form.php @@ -82,6 +82,7 @@ public function checkLocalhostConnection() $this->server->settings->is_reachable = true; $this->server->settings->is_usable = true; $this->server->settings->save(); + $this->dispatch('proxyStatusUpdated'); } else { $this->dispatch('error', 'Server is not reachable.', 'Please validate your configuration and connection.

Check this documentation for further help.

Error: ' . $error); return; diff --git a/app/Models/Server.php b/app/Models/Server.php index bda044320..54cc134aa 100644 --- a/app/Models/Server.php +++ b/app/Models/Server.php @@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Sleep; use Spatie\SchemalessAttributes\Casts\SchemalessAttributes; use Spatie\SchemalessAttributes\SchemalessAttributesTrait; use Illuminate\Support\Str; @@ -239,7 +240,7 @@ public function setupDynamicProxyConfiguration() $dynamic_config_path = $this->proxyPath() . "/dynamic"; if ($this->proxyType() === 'TRAEFIK_V2') { $file = "$dynamic_config_path/coolify.yaml"; - if (empty($settings->fqdn)) { + if (empty($settings->fqdn) || (isCloud() && $this->id !== 0)) { instant_remote_process([ "rm -f $file", ], $this); @@ -358,7 +359,7 @@ public function setupDynamicProxyConfiguration() } } else if ($this->proxyType() === 'CADDY') { $file = "$dynamic_config_path/coolify.caddy"; - if (empty($settings->fqdn)) { + if (empty($settings->fqdn) || (isCloud() && $this->id !== 0)) { instant_remote_process([ "rm -f $file", ], $this); @@ -467,63 +468,53 @@ public function isServerReady(int $tries = 3) if ($this->skipServer()) { return false; } - $serverUptimeCheckNumber = $this->unreachable_count; - if ($this->unreachable_count < $tries) { - $serverUptimeCheckNumber = $this->unreachable_count + 1; - } - if ($this->unreachable_count > $tries) { - $serverUptimeCheckNumber = $tries; - } - - $serverUptimeCheckNumberMax = $tries; - - // ray('server: ' . $this->name); - // ray('serverUptimeCheckNumber: ' . $serverUptimeCheckNumber); - // ray('serverUptimeCheckNumberMax: ' . $serverUptimeCheckNumberMax); - - ['uptime' => $uptime] = $this->validateConnection(); - if ($uptime) { - if ($this->unreachable_notification_sent === true) { - $this->update(['unreachable_notification_sent' => false]); - } - return true; - } else { - if ($serverUptimeCheckNumber >= $serverUptimeCheckNumberMax) { - // Reached max number of retries - if ($this->unreachable_notification_sent === false) { - ray('Server unreachable, sending notification...'); - $this->team?->notify(new Unreachable($this)); - $this->update(['unreachable_notification_sent' => true]); + $checkIteration = 1; + $isServerReady = false; + while ($checkIteration < $tries) { + ['uptime' => $uptime] = $this->validateConnection(); + if ($uptime) { + if ($this->unreachable_notification_sent === true) { + $this->update(['unreachable_notification_sent' => false]); } - if ($this->settings->is_reachable === true) { - $this->settings()->update([ - 'is_reachable' => false, - ]); - } - - foreach ($this->applications() as $application) { - $application->update(['status' => 'exited']); - } - foreach ($this->databases() as $database) { - $database->update(['status' => 'exited']); - } - foreach ($this->services()->get() as $service) { - $apps = $service->applications()->get(); - $dbs = $service->databases()->get(); - foreach ($apps as $app) { - $app->update(['status' => 'exited']); - } - foreach ($dbs as $db) { - $db->update(['status' => 'exited']); - } - } - } else { - $this->update([ - 'unreachable_count' => $this->unreachable_count + 1, + $this->settings()->update([ + 'is_reachable' => true, ]); + $isServerReady = true; + break; + } else { + ray('Server is not ready yet.'); + $checkIteration++; + Sleep::for(10)->seconds(); } - return false; } + if ($isServerReady) { + return $isServerReady; + } + if ($this->unreachable_notification_sent === false) { + ray('Server unreachable, sending notification...'); + $this->team?->notify(new Unreachable($this)); + $this->update(['unreachable_notification_sent' => true]); + } + $this->settings()->update([ + 'is_reachable' => false, + ]); + foreach ($this->applications() as $application) { + $application->update(['status' => 'exited']); + } + foreach ($this->databases() as $database) { + $database->update(['status' => 'exited']); + } + foreach ($this->services()->get() as $service) { + $apps = $service->applications()->get(); + $dbs = $service->databases()->get(); + foreach ($apps as $app) { + $app->update(['status' => 'exited']); + } + foreach ($dbs as $db) { + $db->update(['status' => 'exited']); + } + } + return false; } public function getDiskUsage() { @@ -771,6 +762,11 @@ public function validateConnection() $server->settings()->update([ 'is_reachable' => false, ]); + if (data_get($server, 'unreachable_notification_sent') === false) { + ray('Server unreachable, sending notification...'); + $this->team?->notify(new Unreachable($this)); + $this->update(['unreachable_notification_sent' => true]); + } return ['uptime' => false, 'error' => $e->getMessage()]; } } diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php index 0161b8c95..6c5ec2319 100644 --- a/bootstrap/helpers/shared.php +++ b/bootstrap/helpers/shared.php @@ -988,20 +988,18 @@ function parseDockerComposeFile(Service|Application $resource, bool $isNew = fal if ($fqdns_exploded->count() > 1) { continue; } - if ($resource->server->proxyType() === 'CADDY') { - $env = EnvironmentVariable::where([ - 'key' => $key, - 'service_id' => $resource->id, - ])->first(); - if ($env) { + $env = EnvironmentVariable::where([ + 'key' => $key, + 'service_id' => $resource->id, + ])->first(); + if ($env) { - $env_url = Url::fromString($savedService->fqdn); - $env_port = $env_url->getPort(); - if ($env_port !== $predefinedPort) { - $env_url = $env_url->withPort($predefinedPort); - $savedService->fqdn = $env_url->__toString(); - $savedService->save(); - } + $env_url = Url::fromString($savedService->fqdn); + $env_port = $env_url->getPort(); + if ($env_port !== $predefinedPort) { + $env_url = $env_url->withPort($predefinedPort); + $savedService->fqdn = $env_url->__toString(); + $savedService->save(); } } } diff --git a/config/sentry.php b/config/sentry.php index 75705bd93..6629fefab 100644 --- a/config/sentry.php +++ b/config/sentry.php @@ -7,7 +7,7 @@ // The release version of your application // Example with dynamic git hash: trim(exec('git --git-dir ' . base_path('.git') . ' log --pretty="%h" -n1 HEAD')) - 'release' => '4.0.0-beta.272', + 'release' => '4.0.0-beta.273', // When left empty or `null` the Laravel environment will be used 'environment' => config('app.env'), diff --git a/config/version.php b/config/version.php index cf5c01c23..a5706892f 100644 --- a/config/version.php +++ b/config/version.php @@ -1,3 +1,3 @@ + + + + + + + + + + + diff --git a/resources/views/components/server/navbar.blade.php b/resources/views/components/server/navbar.blade.php index 5afee652c..2130d0031 100644 --- a/resources/views/components/server/navbar.blade.php +++ b/resources/views/components/server/navbar.blade.php @@ -2,13 +2,7 @@

Server

- @if ( - $server->proxyType() !== 'NONE' && - $server->isFunctional() && - !$server->isSwarmWorker() && - !$server->settings->is_build_server) - - @endif +
{{ data_get($server, 'name') }}.
diff --git a/resources/views/livewire/project/resource/index.blade.php b/resources/views/livewire/project/resource/index.blade.php index 28c2de0f4..8a66bc645 100644 --- a/resources/views/livewire/project/resource/index.blade.php +++ b/resources/views/livewire/project/resource/index.blade.php @@ -45,9 +45,9 @@ class="button">+ class="items-center justify-center box">+ Add New Resource @else
- +
-