Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: better server vlaidation fix: remove unnecessary coolify.yaml from cloud hosted servers

Andras Bacsaif4cb7cea211e
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php
index 734063b2ef..1f7006aaa0 100644
--- a/app/Console/Kernel.php
+++ b/app/Console/Kernel.php
@@ -72,13 +72,13 @@ class Kernel extends ConsoleKernel
$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 31683d0972..1383e1f5a8 100644
--- a/app/Jobs/ServerStatusJob.php
+++ b/app/Jobs/ServerStatusJob.php
@@ -38,11 +38,12 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted
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 @@ class ServerStatusJob implements ShouldQueue, ShouldBeEncrypted
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()) {
+ $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/Models/Server.php b/app/Models/Server.php
index bda0443202..8f66f44e73 100644
--- a/app/Models/Server.php
+++ b/app/Models/Server.php
@@ -10,6 +10,7 @@ use Illuminate\Database\Eloquent\Builder;
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 @@ respond 404
$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()) {
instant_remote_process([
"rm -f $file",
], $this);
@@ -467,63 +468,53 @@ $schema://$host {
if ($this->skipServer()) {
return false;
}
- $serverUptimeCheckNumber = $this->unreachable_count;
- if ($this->unreachable_count < $tries) {
- $serverUptimeCheckNumber = $this->unreachable_count + 1;
+ $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]);
+ }
+ $this->settings()->update([
+ 'is_reachable' => true,
+ ]);
+ $isServerReady = true;
+ break;
+ } else {
+ ray('Server is not ready yet.');
+ $checkIteration++;
+ Sleep::for(10)->seconds();
+ }
}
- if ($this->unreachable_count > $tries) {
- $serverUptimeCheckNumber = $tries;
+ if ($isServerReady) {
+ return $isServerReady;
}
-
- $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]);
+ 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']);
}
- 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]);
- }
- 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,
- ]);
+ foreach ($dbs as $db) {
+ $db->update(['status' => 'exited']);
}
- return false;
}
+ return false;
}
public function getDiskUsage()
{