From e3c7c615c67d18df0bf1d18a494f2c88aa7ff6c2 Mon Sep 17 00:00:00 2001 From: Andras Bacsai Date: Tue, 6 Aug 2024 10:53:13 +0200 Subject: [PATCH] refactor: Cleanup unnecessary dynamic proxy configuration in Init command --- app/Console/Commands/Init.php | 37 +++++++++++++++++++++++++++-------- app/Jobs/ServerCheckJob.php | 13 ------------ 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php index 5789d32fc..f5d5a892e 100644 --- a/app/Console/Commands/Init.php +++ b/app/Console/Commands/Init.php @@ -21,13 +21,15 @@ class Init extends Command protected $description = 'Cleanup instance related stuffs'; + public $servers = null; + public function handle() { + $this->servers = Server::all(); $this->alive(); get_public_ips(); if (version_compare('4.0.0-beta.312', config('version'), '<=')) { - $servers = Server::all(); - foreach ($servers as $server) { + foreach ($this->servers as $server) { if ($server->settings->is_metrics_enabled === true) { $server->settings->update(['is_metrics_enabled' => false]); } @@ -57,14 +59,15 @@ class Init extends Command // Required for falsely deleted coolify db $this->restore_coolify_db_backup(); $this->cleanup_unused_network_from_coolify_proxy(); + $this->cleanup_unnecessary_dynamic_proxy_configuration(); $this->cleanup_in_progress_application_deployments(); $this->cleanup_stucked_helper_containers(); $this->call('cleanup:queue'); $this->call('cleanup:stucked-resources'); if (! isCloud()) { try { - $server = Server::find(0)->first(); - $server->setupDynamicProxyConfiguration(); + $localhost = $this->servers->where('id', 0)->first(); + $localhost->setupDynamicProxyConfiguration(); } catch (\Throwable $e) { echo "Could not setup dynamic configuration: {$e->getMessage()}\n"; } @@ -85,11 +88,30 @@ class Init extends Command $this->call('cleanup:stucked-resources'); } + private function cleanup_unnecessary_dynamic_proxy_configuration() + { + if (isCloud()) { + foreach ($this->servers as $server) { + if (! $server->isFunctional()) { + continue; + } + if ($server->id === 0) { + continue; + } + $file = $server->proxyPath().'/dynamic/coolify.yaml'; + + return instant_remote_process([ + "rm -f $file", + ], $server, false); + + } + } + } + private function cleanup_unused_network_from_coolify_proxy() { ray()->clearAll(); - $servers = Server::all(); - foreach ($servers as $server) { + foreach ($this->servers as $server) { if (! $server->isFunctional()) { continue; } @@ -150,8 +172,7 @@ class Init extends Command private function cleanup_stucked_helper_containers() { - $servers = Server::all(); - foreach ($servers as $server) { + foreach ($this->servers as $server) { if ($server->isFunctional()) { CleanupHelperContainersJob::dispatch($server); } diff --git a/app/Jobs/ServerCheckJob.php b/app/Jobs/ServerCheckJob.php index 88caaacc4..6a2233726 100644 --- a/app/Jobs/ServerCheckJob.php +++ b/app/Jobs/ServerCheckJob.php @@ -106,7 +106,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue private function serverStatus() { - $this->removeUnnevessaryCoolifyYaml(); ['uptime' => $uptime] = $this->server->validateConnection(); if ($uptime) { if ($this->server->unreachable_notification_sent === true) { @@ -138,18 +137,6 @@ class ServerCheckJob implements ShouldBeEncrypted, ShouldQueue } - private function removeUnnevessaryCoolifyYaml() - { - // 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); - } - } - private function checkLogDrainContainer() { $foundLogDrainContainer = $this->containers->filter(function ($value, $key) {