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.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
feat: disk cleanup threshold by server
Andras Bacsai18d26904e2f6
diff --git a/app/Console/Kernel.php b/app/Console/Kernel.phpindex 0faaf49676..1d20b7606e 100644--- a/app/Console/Kernel.php+++ b/app/Console/Kernel.php@@ -14,12 +14,11 @@ class Kernel extends ConsoleKernel{if (isDev()) {$schedule->command('horizon:snapshot')->everyMinute();- // $schedule->job(new DockerCleanupJob)->everyMinute();+ // $schedule->job(new DockerCleanupJob)->everyOddHour();// $schedule->job(new InstanceAutoUpdateJob(true))->everyMinute();} else {$schedule->command('horizon:snapshot')->everyFiveMinutes();- $schedule->job(new DockerCleanupJob)->everyFiveMinutes();-+ $schedule->job(new DockerCleanupJob)->everyTenMinutes();$schedule->job(new ProxyCheckJob)->everyFiveMinutes();$schedule->job(new InstanceAutoUpdateJob)->everyTenMinutes();}@@ -30,4 +29,4 @@ class Kernel extends ConsoleKernelrequire base_path('routes/console.php');}-}+}\ No newline at end of filediff --git a/app/Http/Livewire/Server/Form.php b/app/Http/Livewire/Server/Form.phpindex 72d32243ff..fc98c05bfb 100644--- a/app/Http/Livewire/Server/Form.php+++ b/app/Http/Livewire/Server/Form.php@@ -12,6 +12,7 @@ class Form extends Componentpublic $uptime;public $dockerVersion;public string|null $wildcard_domain = null;+ public int $cleanup_after_percentage;protected $rules = ['server.name' => 'required|min:6',@@ -35,6 +36,7 @@ class Form extends Componentpublic function mount(){$this->wildcard_domain = $this->server->settings->wildcard_domain;+ $this->cleanup_after_percentage = $this->server->settings->cleanup_after_percentage;}public function installDocker(){@@ -91,8 +93,9 @@ class Form extends Component// return;// }$this->server->settings->wildcard_domain = $this->wildcard_domain;+ $this->server->settings->cleanup_after_percentage = $this->cleanup_after_percentage;$this->server->settings->save();$this->server->save();$this->emit('success', 'Server updated successfully.');}-}+}\ No newline at end of filediff --git a/app/Jobs/DockerCleanupJob.php b/app/Jobs/DockerCleanupJob.phpindex 9e9258cd53..117a9bd8a3 100644--- a/app/Jobs/DockerCleanupJob.php+++ b/app/Jobs/DockerCleanupJob.php@@ -38,15 +38,14 @@ class DockerCleanupJob implements ShouldQueue}$disk_usage = json_decode(instant_remote_process(['df -hP | awk \'BEGIN {printf"{\"disks\":["}{if($1=="Filesystem")next;if(a)printf",";printf"{\"mount\":\""$6"\",\"size\":\""$2"\",\"used\":\""$3"\",\"avail\":\""$4"\",\"use%\":\""$5"\"}";a++;}END{print"]}";}\''], $server), true);$mount_point = collect(data_get($disk_usage, 'disks'))->where('mount', $docker_root_filesystem)->first();- if (Str::of(data_get($mount_point, 'use%'))->trim()->replace('%', '')->value() > 60) {- continue;+ if (Str::of(data_get($mount_point, 'use%'))->trim()->replace('%', '')->value() >= $server->settings->cleanup_after_percentage) {+ instant_remote_process(['docker image prune -af'], $server);+ instant_remote_process(['docker container prune -f --filter "label=coolify.managed=true"'], $server);+ instant_remote_process(['docker builder prune -af'], $server);}- instant_remote_process(['docker image prune -af'], $server);- instant_remote_process(['docker container prune -f --filter "label=coolify.managed=true"'], $server);- instant_remote_process(['docker builder prune -af'], $server);}} catch (\Exception $e) {Log::error($e->getMessage());}}-}+}\ No newline at end of filediff --git a/database/migrations/2023_06_23_114133_use_application_deployment_queues_as_activity.php b/database/migrations/2023_06_23_114133_use_application_deployment_queues_as_activity.phpindex 36623ee7bc..642184abc3 100644--- a/database/migrations/2023_06_23_114133_use_application_deployment_queues_as_activity.php+++ b/database/migrations/2023_06_23_114133_use_application_deployment_queues_as_activity.php@@ -27,4 +27,4 @@ return new class extends Migration$table->dropColumn('current_process_id');});}-};+};\ No newline at end of filediff --git a/database/migrations/2023_06_23_114134_add_disk_usage_percentage_to_servers.php b/database/migrations/2023_06_23_114134_add_disk_usage_percentage_to_servers.phpnew file mode 100644index 0000000000..d2b0f892ca--- /dev/null+++ b/database/migrations/2023_06_23_114134_add_disk_usage_percentage_to_servers.php@@ -0,0 +1,28 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('server_settings', function (Blueprint $table) {+ $table->integer('cleanup_after_percentage')->default(80);+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('server_settings', function (Blueprint $table) {+ $table->dropColumn('cleanup_after_percentage');+ });+ }+};\ No newline at end of filediff --git a/resources/views/livewire/server/form.blade.php b/resources/views/livewire/server/form.blade.phpindex 4a88910acc..ce7720fc6f 100644--- a/resources/views/livewire/server/form.blade.php+++ b/resources/views/livewire/server/form.blade.php@@ -33,6 +33,10 @@</div></div></div>+ <h3 class="py-4">Settings</h3>+ <div class="flex items-center w-64 gap-2">+ <x-forms.input id="cleanup_after_percentage" label="Disk Cleanup threshold (%)" required helper="Disk cleanup job will be executed if disk usage is more than this number."/>+ </div><h3 class="py-4">Actions</h3>@if ($server->settings->is_reachable)<div class="flex items-center gap-2">