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.

refactor: Cleanup unnecessary dynamic proxy configuration in Init command

Andras Bacsaie3c7c615c67d
diff --git a/app/Console/Commands/Init.php b/app/Console/Commands/Init.php
index 5789d32fc1..f5d5a892ed 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 88caaacc47..6a2233726d 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) {