fixes and check for valid cron expressions
This commit is contained in:
@@ -20,7 +20,6 @@ class UpdateCoolify
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$settings = InstanceSettings::get();
|
$settings = InstanceSettings::get();
|
||||||
ray('Running InstanceAutoUpdateJob');
|
|
||||||
$this->server = Server::find(0);
|
$this->server = Server::find(0);
|
||||||
if (! $this->server) {
|
if (! $this->server) {
|
||||||
return;
|
return;
|
||||||
@@ -48,7 +47,6 @@ class UpdateCoolify
|
|||||||
private function update()
|
private function update()
|
||||||
{
|
{
|
||||||
if (isDev()) {
|
if (isDev()) {
|
||||||
ray('Running in dev mode');
|
|
||||||
remote_process([
|
remote_process([
|
||||||
'sleep 10',
|
'sleep 10',
|
||||||
], $this->server);
|
], $this->server);
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ use App\Jobs\PullSentinelImageJob;
|
|||||||
use App\Jobs\PullTemplatesFromCDN;
|
use App\Jobs\PullTemplatesFromCDN;
|
||||||
use App\Jobs\ScheduledTaskJob;
|
use App\Jobs\ScheduledTaskJob;
|
||||||
use App\Jobs\ServerStatusJob;
|
use App\Jobs\ServerStatusJob;
|
||||||
|
use App\Jobs\UpdateCoolifyJob;
|
||||||
|
use App\Jobs\CheckForUpdatesJob;
|
||||||
use App\Models\InstanceSettings;
|
use App\Models\InstanceSettings;
|
||||||
use App\Models\ScheduledDatabaseBackup;
|
use App\Models\ScheduledDatabaseBackup;
|
||||||
use App\Models\ScheduledTask;
|
use App\Models\ScheduledTask;
|
||||||
@@ -31,10 +33,6 @@ class Kernel extends ConsoleKernel
|
|||||||
$settings = InstanceSettings::get();
|
$settings = InstanceSettings::get();
|
||||||
|
|
||||||
if (isDev()) {
|
if (isDev()) {
|
||||||
// Instance Jobs
|
|
||||||
$schedule->command('horizon:snapshot')->everyMinute();
|
|
||||||
$schedule->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
|
|
||||||
$schedule->job(new PullTemplatesFromCDN)->everyTwoHours()->onOneServer();
|
|
||||||
// Server Jobs
|
// Server Jobs
|
||||||
$this->check_scheduled_backups($schedule);
|
$this->check_scheduled_backups($schedule);
|
||||||
$this->check_resources($schedule);
|
$this->check_resources($schedule);
|
||||||
@@ -45,9 +43,15 @@ class Kernel extends ConsoleKernel
|
|||||||
// Instance Jobs
|
// Instance Jobs
|
||||||
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
$schedule->command('horizon:snapshot')->everyFiveMinutes();
|
||||||
$schedule->command('cleanup:unreachable-servers')->daily();
|
$schedule->command('cleanup:unreachable-servers')->daily();
|
||||||
|
$schedule->job(new PullTemplatesFromCDN)->daily()->onOneServer();
|
||||||
|
$schedule->job(new CleanupInstanceStuffsJob)->everyFiveMinutes()->onOneServer();
|
||||||
|
|
||||||
|
if ($settings->update_check_frequency && $this->isValidCronExpression($settings->update_check_frequency)) {
|
||||||
$schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();
|
$schedule->job(new PullCoolifyImageJob)->cron($settings->update_check_frequency)->onOneServer();
|
||||||
$schedule->job(new PullTemplatesFromCDN)->everyThirtyMinutes()->onOneServer();
|
} else {
|
||||||
$schedule->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
|
// Default to every 12 hours if not set or invalid
|
||||||
|
$schedule->job(new PullCoolifyImageJob)->twiceDaily()->onOneServer();
|
||||||
|
}
|
||||||
|
|
||||||
// Server Jobs
|
// Server Jobs
|
||||||
$this->scheduleUpdates($schedule);
|
$this->scheduleUpdates($schedule);
|
||||||
@@ -56,7 +60,6 @@ class Kernel extends ConsoleKernel
|
|||||||
$this->check_scheduled_tasks($schedule);
|
$this->check_scheduled_tasks($schedule);
|
||||||
$this->check_scheduled_backups($schedule);
|
$this->check_scheduled_backups($schedule);
|
||||||
|
|
||||||
|
|
||||||
$schedule->command('cleanup:database --yes')->daily();
|
$schedule->command('cleanup:database --yes')->daily();
|
||||||
$schedule->command('uploads:clear')->everyTwoMinutes();
|
$schedule->command('uploads:clear')->everyTwoMinutes();
|
||||||
}
|
}
|
||||||
@@ -79,13 +82,31 @@ class Kernel extends ConsoleKernel
|
|||||||
$settings = InstanceSettings::get();
|
$settings = InstanceSettings::get();
|
||||||
|
|
||||||
// Schedule update check
|
// Schedule update check
|
||||||
if ($settings->update_check_frequency) {
|
if ($settings->update_check_frequency && $this->isValidCronExpression($settings->update_check_frequency)) {
|
||||||
$schedule->job(new CheckForUpdatesJob())->cron($settings->update_check_frequency)->onOneServer();
|
$schedule->job(new CheckForUpdatesJob())->cron($settings->update_check_frequency)->onOneServer();
|
||||||
|
} else {
|
||||||
|
// Default to every 12 hours if not set or invalid
|
||||||
|
$schedule->job(new CheckForUpdatesJob())->twiceDaily()->onOneServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Schedule auto-update
|
// Schedule auto-update
|
||||||
if ($settings->is_auto_update_enabled && $settings->auto_update_frequency) {
|
if ($settings->is_auto_update_enabled) {
|
||||||
|
if ($settings->auto_update_frequency && $this->isValidCronExpression($settings->auto_update_frequency)) {
|
||||||
$schedule->job(new UpdateCoolifyJob())->cron($settings->auto_update_frequency)->onOneServer();
|
$schedule->job(new UpdateCoolifyJob())->cron($settings->auto_update_frequency)->onOneServer();
|
||||||
|
} else {
|
||||||
|
// Default to every 24 hours if not set or invalid
|
||||||
|
$schedule->job(new UpdateCoolifyJob())->daily()->onOneServer();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function isValidCronExpression($expression)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
new \Cron\CronExpression($expression);
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -33,14 +33,12 @@ class CheckForUpdatesJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
if (version_compare($latest_version, $current_version, '>')) {
|
if (version_compare($latest_version, $current_version, '>')) {
|
||||||
// New version available
|
// New version available
|
||||||
$settings->update(['new_version_available' => true]);
|
$settings->update(['new_version_available' => true]);
|
||||||
// Optionally, you can trigger a notification here
|
|
||||||
} else {
|
} else {
|
||||||
$settings->update(['new_version_available' => false]);
|
$settings->update(['new_version_available' => false]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// Log the error or send a notification
|
// Consider implementing a notification to administrators
|
||||||
ray('CheckForUpdatesJob failed: ' . $e->getMessage());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,6 @@ class PullCoolifyImageJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
if (version_compare($latest_version, $current_version, '<')) {
|
if (version_compare($latest_version, $current_version, '<')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// The actual update process will be handled by the UpdateCoolifyJob
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs;
|
||||||
|
|
||||||
use App\Actions\Server\UpdateCoolify;
|
|
||||||
use App\Models\InstanceSettings;
|
use App\Models\InstanceSettings;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
@@ -11,6 +10,8 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
|||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use App\Actions\Server\UpdateCoolify;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class UpdateCoolifyJob implements ShouldBeEncrypted, ShouldQueue
|
class UpdateCoolifyJob implements ShouldBeEncrypted, ShouldQueue
|
||||||
{
|
{
|
||||||
@@ -22,23 +23,31 @@ class UpdateCoolifyJob implements ShouldBeEncrypted, ShouldQueue
|
|||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$settings = InstanceSettings::get();
|
$settings = InstanceSettings::get();
|
||||||
if (!$settings->is_auto_update_enabled || !$settings->new_version_available) {
|
if (!$settings->is_auto_update_enabled) {
|
||||||
|
Log::info('Auto-update is disabled. Skipping update check.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$settings->new_version_available) {
|
||||||
|
Log::info('No new version available. Skipping update.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$server = Server::findOrFail(0);
|
$server = Server::findOrFail(0);
|
||||||
if (!$server) {
|
if (!$server) {
|
||||||
|
Log::error('Server not found. Cannot proceed with update.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log::info('Starting Coolify update process...');
|
||||||
UpdateCoolify::run(false); // false means it's not a manual update
|
UpdateCoolify::run(false); // false means it's not a manual update
|
||||||
|
|
||||||
// After successful update, reset the new_version_available flag
|
|
||||||
$settings->update(['new_version_available' => false]);
|
$settings->update(['new_version_available' => false]);
|
||||||
|
Log::info('Coolify update completed successfully.');
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
// Log the error or send a notification
|
Log::error('UpdateCoolifyJob failed: ' . $e->getMessage());
|
||||||
ray('UpdateCoolifyJob failed: ' . $e->getMessage());
|
// Consider implementing a notification to administrators
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,7 @@ namespace App\Livewire\Settings;
|
|||||||
use App\Models\InstanceSettings as ModelsInstanceSettings;
|
use App\Models\InstanceSettings as ModelsInstanceSettings;
|
||||||
use App\Models\Server;
|
use App\Models\Server;
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
|
use Cron\CronExpression;
|
||||||
|
|
||||||
class Configuration extends Component
|
class Configuration extends Component
|
||||||
{
|
{
|
||||||
@@ -20,6 +21,10 @@ class Configuration extends Component
|
|||||||
|
|
||||||
public bool $is_api_enabled;
|
public bool $is_api_enabled;
|
||||||
|
|
||||||
|
public ?string $auto_update_frequency;
|
||||||
|
|
||||||
|
public ?string $update_check_frequency;
|
||||||
|
|
||||||
protected string $dynamic_config_path = '/data/coolify/proxy/dynamic';
|
protected string $dynamic_config_path = '/data/coolify/proxy/dynamic';
|
||||||
|
|
||||||
protected Server $server;
|
protected Server $server;
|
||||||
@@ -32,6 +37,9 @@ class Configuration extends Component
|
|||||||
'settings.custom_dns_servers' => 'nullable',
|
'settings.custom_dns_servers' => 'nullable',
|
||||||
'settings.instance_name' => 'nullable',
|
'settings.instance_name' => 'nullable',
|
||||||
'settings.allowed_ips' => 'nullable',
|
'settings.allowed_ips' => 'nullable',
|
||||||
|
'settings.is_auto_update_enabled' => 'boolean',
|
||||||
|
'auto_update_frequency' => 'nullable|string',
|
||||||
|
'update_check_frequency' => 'required|string',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $validationAttributes = [
|
protected $validationAttributes = [
|
||||||
@@ -41,6 +49,9 @@ class Configuration extends Component
|
|||||||
'settings.public_port_max' => 'Public port max',
|
'settings.public_port_max' => 'Public port max',
|
||||||
'settings.custom_dns_servers' => 'Custom DNS servers',
|
'settings.custom_dns_servers' => 'Custom DNS servers',
|
||||||
'settings.allowed_ips' => 'Allowed IPs',
|
'settings.allowed_ips' => 'Allowed IPs',
|
||||||
|
'settings.is_auto_update_enabled' => 'Auto Update Enabled',
|
||||||
|
'auto_update_frequency' => 'Auto Update Frequency',
|
||||||
|
'update_check_frequency' => 'Update Check Frequency',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function mount()
|
public function mount()
|
||||||
@@ -50,6 +61,8 @@ class Configuration extends Component
|
|||||||
$this->is_registration_enabled = $this->settings->is_registration_enabled;
|
$this->is_registration_enabled = $this->settings->is_registration_enabled;
|
||||||
$this->is_dns_validation_enabled = $this->settings->is_dns_validation_enabled;
|
$this->is_dns_validation_enabled = $this->settings->is_dns_validation_enabled;
|
||||||
$this->is_api_enabled = $this->settings->is_api_enabled;
|
$this->is_api_enabled = $this->settings->is_api_enabled;
|
||||||
|
$this->auto_update_frequency = $this->settings->auto_update_frequency;
|
||||||
|
$this->update_check_frequency = $this->settings->update_check_frequency;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function instantSave()
|
public function instantSave()
|
||||||
@@ -59,6 +72,8 @@ class Configuration extends Component
|
|||||||
$this->settings->is_registration_enabled = $this->is_registration_enabled;
|
$this->settings->is_registration_enabled = $this->is_registration_enabled;
|
||||||
$this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
|
$this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
|
||||||
$this->settings->is_api_enabled = $this->is_api_enabled;
|
$this->settings->is_api_enabled = $this->is_api_enabled;
|
||||||
|
$this->settings->auto_update_frequency = $this->auto_update_frequency;
|
||||||
|
$this->settings->update_check_frequency = $this->update_check_frequency;
|
||||||
$this->settings->save();
|
$this->settings->save();
|
||||||
$this->dispatch('success', 'Settings updated!');
|
$this->dispatch('success', 'Settings updated!');
|
||||||
}
|
}
|
||||||
@@ -76,6 +91,16 @@ class Configuration extends Component
|
|||||||
}
|
}
|
||||||
$this->validate();
|
$this->validate();
|
||||||
|
|
||||||
|
if ($this->is_auto_update_enabled && !$this->validateCronExpression($this->auto_update_frequency)) {
|
||||||
|
$this->dispatch('error', 'Invalid Cron / Human expression for Auto Update Frequency.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$this->validateCronExpression($this->update_check_frequency)) {
|
||||||
|
$this->dispatch('error', 'Invalid Cron / Human expression for Update Check Frequency.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->settings->is_dns_validation_enabled && $this->settings->fqdn) {
|
if ($this->settings->is_dns_validation_enabled && $this->settings->fqdn) {
|
||||||
if (! validate_dns_entry($this->settings->fqdn, $this->server)) {
|
if (! validate_dns_entry($this->settings->fqdn, $this->server)) {
|
||||||
$this->dispatch('error', "Validating DNS failed.<br><br>Make sure you have added the DNS records correctly.<br><br>{$this->settings->fqdn}->{$this->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
|
$this->dispatch('error', "Validating DNS failed.<br><br>Make sure you have added the DNS records correctly.<br><br>{$this->settings->fqdn}->{$this->server->ip}<br><br>Check this <a target='_blank' class='underline dark:text-white' href='https://coolify.io/docs/knowledge-base/dns-configuration'>documentation</a> for further help.");
|
||||||
@@ -99,6 +124,14 @@ class Configuration extends Component
|
|||||||
$this->settings->allowed_ips = $this->settings->allowed_ips->unique();
|
$this->settings->allowed_ips = $this->settings->allowed_ips->unique();
|
||||||
$this->settings->allowed_ips = $this->settings->allowed_ips->implode(',');
|
$this->settings->allowed_ips = $this->settings->allowed_ips->implode(',');
|
||||||
|
|
||||||
|
$this->settings->do_not_track = $this->do_not_track;
|
||||||
|
$this->settings->is_auto_update_enabled = $this->is_auto_update_enabled;
|
||||||
|
$this->settings->is_registration_enabled = $this->is_registration_enabled;
|
||||||
|
$this->settings->is_dns_validation_enabled = $this->is_dns_validation_enabled;
|
||||||
|
$this->settings->is_api_enabled = $this->is_api_enabled;
|
||||||
|
$this->settings->auto_update_frequency = $this->auto_update_frequency;
|
||||||
|
$this->settings->update_check_frequency = $this->update_check_frequency;
|
||||||
|
|
||||||
$this->settings->save();
|
$this->settings->save();
|
||||||
$this->server->setupDynamicProxyConfiguration();
|
$this->server->setupDynamicProxyConfiguration();
|
||||||
if (! $error_show) {
|
if (! $error_show) {
|
||||||
@@ -108,4 +141,38 @@ class Configuration extends Component
|
|||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function validateCronExpression($expression): bool
|
||||||
|
{
|
||||||
|
if (empty($expression)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$isValid = false;
|
||||||
|
try {
|
||||||
|
$cronExpression = new CronExpression($expression);
|
||||||
|
$isValid = $cronExpression->getNextRunDate() !== false;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset(VALID_CRON_STRINGS[$expression])) {
|
||||||
|
$isValid = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $isValid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatedAutoUpdateFrequency()
|
||||||
|
{
|
||||||
|
if (!$this->validateCronExpression($this->auto_update_frequency)) {
|
||||||
|
$this->dispatch('error', 'Invalid Cron / Human expression.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updatedUpdateCheckFrequency()
|
||||||
|
{
|
||||||
|
if (!$this->validateCronExpression($this->update_check_frequency)) {
|
||||||
|
$this->dispatch('error', 'Invalid Cron / Human expression.');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -18,6 +18,9 @@ class InstanceSettings extends Model implements SendsEmail
|
|||||||
'resale_license' => 'encrypted',
|
'resale_license' => 'encrypted',
|
||||||
'smtp_password' => 'encrypted',
|
'smtp_password' => 'encrypted',
|
||||||
'allowed_ip_ranges' => 'array',
|
'allowed_ip_ranges' => 'array',
|
||||||
|
'is_auto_update_enabled' => 'boolean',
|
||||||
|
'auto_update_frequency' => 'string',
|
||||||
|
'update_check_frequency' => 'string',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function fqdn(): Attribute
|
public function fqdn(): Attribute
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ return new class extends Migration
|
|||||||
public function up(): void
|
public function up(): void
|
||||||
{
|
{
|
||||||
Schema::table('instance_settings', function (Blueprint $table) {
|
Schema::table('instance_settings', function (Blueprint $table) {
|
||||||
$table->string('update_check_frequency')->nullable();
|
$table->string('update_check_frequency')->default('0 */12 * * *')->nullable();
|
||||||
$table->string('auto_update_frequency')->nullable();
|
$table->string('auto_update_frequency')->default('0 0 * * *')->nullable();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,8 +46,10 @@
|
|||||||
<x-forms.checkbox instantSave id="is_auto_update_enabled" label="Auto Update Coolify" />
|
<x-forms.checkbox instantSave id="is_auto_update_enabled" label="Auto Update Coolify" />
|
||||||
@if($is_auto_update_enabled)
|
@if($is_auto_update_enabled)
|
||||||
<x-forms.input id="auto_update_frequency" label="Auto Update Frequency" placeholder="0 0 * * *" helper="Cron expression for auto update frequency" />
|
<x-forms.input id="auto_update_frequency" label="Auto Update Frequency" placeholder="0 0 * * *" helper="Cron expression for auto update frequency" />
|
||||||
|
@error('settings.auto_update_frequency') <span class="text-error">{{ $message }}</span> @enderror
|
||||||
@endif
|
@endif
|
||||||
<x-forms.input id="update_check_frequency" label="Update Check Frequency" placeholder="0 0 * * *" helper="Cron expression for update check frequency" />
|
<x-forms.input id="update_check_frequency" label="Update Check Frequency" placeholder="0 */12 * * *" helper="Cron expression for update check frequency" />
|
||||||
|
@error('settings.update_check_frequency') <span class="text-error">{{ $message }}</span> @enderror
|
||||||
@endif
|
@endif
|
||||||
<x-forms.checkbox instantSave id="is_registration_enabled" label="Registration Allowed" />
|
<x-forms.checkbox instantSave id="is_registration_enabled" label="Registration Allowed" />
|
||||||
<x-forms.checkbox instantSave id="do_not_track" label="Do Not Track" />
|
<x-forms.checkbox instantSave id="do_not_track" label="Do Not Track" />
|
||||||
|
|||||||
Reference in New Issue
Block a user