diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 2ed3ee454..c58ef2187 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -133,14 +133,14 @@ class Kernel extends ConsoleKernel foreach ($servers as $server) { $serverTimezone = data_get($server->settings, 'server_timezone', $this->instanceTimezone); + if (validate_timezone($serverTimezone) === false) { + $serverTimezone = config('app.timezone'); + } // Sentinel check $lastSentinelUpdate = $server->sentinel_updated_at; if (Carbon::parse($lastSentinelUpdate)->isBefore(now()->subSeconds($server->waitBeforeDoingSshCheck()))) { // Check container status every minute if Sentinel does not activated - if (validate_timezone($serverTimezone) === false) { - $serverTimezone = config('app.timezone'); - } if (isCloud()) { $this->scheduleInstance->job(new ServerCheckJob($server))->timezone($serverTimezone)->everyFiveMinutes()->onOneServer(); } else { @@ -148,15 +148,11 @@ class Kernel extends ConsoleKernel } // $this->scheduleInstance->job(new \App\Jobs\ServerCheckNewJob($server))->everyFiveMinutes()->onOneServer(); - // Check storage usage every 10 minutes if Sentinel does not activated - $this->scheduleInstance->job(new ServerStorageCheckJob($server))->everyTenMinutes()->onOneServer(); - } - if ($server->settings->force_docker_cleanup) { - $this->scheduleInstance->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer(); - } else { - $this->scheduleInstance->job(new DockerCleanupJob($server))->everyTenMinutes()->timezone($serverTimezone)->onOneServer(); + $this->scheduleInstance->job(new ServerStorageCheckJob($server))->cron($server->settings->server_disk_usage_check_frequency)->timezone($serverTimezone)->onOneServer(); } + $this->scheduleInstance->job(new DockerCleanupJob($server))->cron($server->settings->docker_cleanup_frequency)->timezone($serverTimezone)->onOneServer(); + // Cleanup multiplexed connections every hour // $this->scheduleInstance->job(new ServerCleanupMux($server))->hourly()->onOneServer(); diff --git a/app/Livewire/Server/Advanced.php b/app/Livewire/Server/Advanced.php index 0650de9a0..577730f24 100644 --- a/app/Livewire/Server/Advanced.php +++ b/app/Livewire/Server/Advanced.php @@ -13,14 +13,11 @@ class Advanced extends Component public array $parameters = []; - #[Validate(['integer', 'min:1'])] - public int $concurrentBuilds = 1; + #[Validate(['string'])] + public string $serverDiskUsageCheckFrequency = '0 23 * * *'; - #[Validate(['integer', 'min:1'])] - public int $dynamicTimeout = 1; - - #[Validate('boolean')] - public bool $forceDockerCleanup = false; + #[Validate(['integer', 'min:1', 'max:99'])] + public int $serverDiskUsageNotificationThreshold = 50; #[Validate(['string', 'required'])] public string $dockerCleanupFrequency = '*/10 * * * *'; @@ -28,8 +25,8 @@ class Advanced extends Component #[Validate(['integer', 'min:1', 'max:99'])] public int $dockerCleanupThreshold = 10; - #[Validate(['integer', 'min:1', 'max:99'])] - public int $serverDiskUsageNotificationThreshold = 50; + #[Validate('boolean')] + public bool $forceDockerCleanup = false; #[Validate('boolean')] public bool $deleteUnusedVolumes = false; @@ -37,6 +34,12 @@ class Advanced extends Component #[Validate('boolean')] public bool $deleteUnusedNetworks = false; + #[Validate(['integer', 'min:1'])] + public int $concurrentBuilds = 1; + + #[Validate(['integer', 'min:1'])] + public int $dynamicTimeout = 1; + public function mount(string $server_uuid) { try { @@ -60,6 +63,7 @@ class Advanced extends Component $this->server->settings->server_disk_usage_notification_threshold = $this->serverDiskUsageNotificationThreshold; $this->server->settings->delete_unused_volumes = $this->deleteUnusedVolumes; $this->server->settings->delete_unused_networks = $this->deleteUnusedNetworks; + $this->server->settings->server_disk_usage_check_frequency = $this->serverDiskUsageCheckFrequency; $this->server->settings->save(); } else { $this->concurrentBuilds = $this->server->settings->concurrent_builds; @@ -70,6 +74,7 @@ class Advanced extends Component $this->serverDiskUsageNotificationThreshold = $this->server->settings->server_disk_usage_notification_threshold; $this->deleteUnusedVolumes = $this->server->settings->delete_unused_volumes; $this->deleteUnusedNetworks = $this->server->settings->delete_unused_networks; + $this->serverDiskUsageCheckFrequency = $this->server->settings->server_disk_usage_check_frequency; } } @@ -100,6 +105,10 @@ class Advanced extends Component $this->dockerCleanupFrequency = $this->server->settings->getOriginal('docker_cleanup_frequency'); throw new \Exception('Invalid Cron / Human expression for Docker Cleanup Frequency.'); } + if (! validate_cron_expression($this->serverDiskUsageCheckFrequency)) { + $this->serverDiskUsageCheckFrequency = $this->server->settings->getOriginal('server_disk_usage_check_frequency'); + throw new \Exception('Invalid Cron / Human expression for Disk Usage Check Frequency.'); + } $this->syncData(true); $this->dispatch('success', 'Server updated.'); } catch (\Throwable $e) { diff --git a/database/migrations/2024_12_17_140637_add_server_disk_usage_check_frequency_to_server_settings_table.php b/database/migrations/2024_12_17_140637_add_server_disk_usage_check_frequency_to_server_settings_table.php new file mode 100644 index 000000000..be0f4bc0f --- /dev/null +++ b/database/migrations/2024_12_17_140637_add_server_disk_usage_check_frequency_to_server_settings_table.php @@ -0,0 +1,28 @@ +string('server_disk_usage_check_frequency')->default('0 23 * * *'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('server_settings', function (Blueprint $table) { + $table->dropColumn('server_disk_usage_check_frequency'); + }); + } +}; diff --git a/resources/views/livewire/server/advanced.blade.php b/resources/views/livewire/server/advanced.blade.php index 4d32d711c..40ff6c8b5 100644 --- a/resources/views/livewire/server/advanced.blade.php +++ b/resources/views/livewire/server/advanced.blade.php @@ -10,40 +10,44 @@

Advanced

Save -
-
Advanced configuration for your server.
+
Advanced configuration for your server.
-
+

Disk Usage

+
+
+
-
+

Docker Cleanup

+
- @if ($forceDockerCleanup) - - @else - + + @if (!$forceDockerCleanup) + @endif