2023-03-17 15:33:48 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Console;
|
|
|
|
|
|
2026-04-20 14:28:38 +02:00
|
|
|
use App\Jobs\ApiTokenExpirationWarningJob;
|
2024-08-06 14:36:56 +02:00
|
|
|
use App\Jobs\CheckForUpdatesJob;
|
2024-10-21 12:06:13 +02:00
|
|
|
use App\Jobs\CheckHelperImageJob;
|
2025-11-13 13:38:57 +01:00
|
|
|
use App\Jobs\CheckTraefikVersionJob;
|
2023-08-15 14:11:38 +02:00
|
|
|
use App\Jobs\CleanupInstanceStuffsJob;
|
2025-12-08 17:15:52 +01:00
|
|
|
use App\Jobs\CleanupOrphanedPreviewContainersJob;
|
2026-06-02 14:05:26 +02:00
|
|
|
use App\Jobs\CleanupStaleMultiplexedConnections;
|
2025-09-01 16:13:55 +02:00
|
|
|
use App\Jobs\PullChangelog;
|
2024-05-30 12:56:29 +02:00
|
|
|
use App\Jobs\PullTemplatesFromCDN;
|
2025-02-05 22:11:10 +01:00
|
|
|
use App\Jobs\RegenerateSslCertJob;
|
2025-07-12 14:44:52 +02:00
|
|
|
use App\Jobs\ScheduledJobManager;
|
2025-08-22 11:50:56 +02:00
|
|
|
use App\Jobs\ServerManagerJob;
|
2024-08-05 20:05:38 +02:00
|
|
|
use App\Jobs\UpdateCoolifyJob;
|
2024-11-02 12:38:22 +01:00
|
|
|
use App\Models\InstanceSettings;
|
2023-03-17 15:33:48 +01:00
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
|
|
|
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
|
|
|
|
|
|
|
|
|
class Kernel extends ConsoleKernel
|
|
|
|
|
{
|
2024-11-14 10:56:56 +01:00
|
|
|
private Schedule $scheduleInstance;
|
|
|
|
|
|
2024-11-02 12:38:22 +01:00
|
|
|
private InstanceSettings $settings;
|
|
|
|
|
|
2024-11-06 15:16:12 +01:00
|
|
|
private string $updateCheckFrequency;
|
|
|
|
|
|
|
|
|
|
private string $instanceTimezone;
|
|
|
|
|
|
2023-03-17 15:33:48 +01:00
|
|
|
protected function schedule(Schedule $schedule): void
|
|
|
|
|
{
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->scheduleInstance = $schedule;
|
2024-11-02 12:38:22 +01:00
|
|
|
$this->settings = instanceSettings();
|
2024-11-06 15:16:12 +01:00
|
|
|
$this->updateCheckFrequency = $this->settings->update_check_frequency ?: '0 * * * *';
|
2024-11-14 10:56:56 +01:00
|
|
|
|
2024-11-06 15:16:12 +01:00
|
|
|
$this->instanceTimezone = $this->settings->instance_timezone ?: config('app.timezone');
|
2024-08-05 16:31:41 +02:00
|
|
|
|
2024-11-14 10:56:56 +01:00
|
|
|
if (validate_timezone($this->instanceTimezone) === false) {
|
|
|
|
|
$this->instanceTimezone = config('app.timezone');
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 14:05:26 +02:00
|
|
|
$this->scheduleInstance->call(fn () => app(CleanupStaleMultiplexedConnections::class)->handle())
|
|
|
|
|
->name('cleanup:ssh-mux')
|
|
|
|
|
->hourly()
|
|
|
|
|
->when(fn () => config('constants.ssh.mux_enabled') && ! config('constants.coolify.is_windows_docker_desktop'));
|
2026-02-25 12:07:29 +01:00
|
|
|
$this->scheduleInstance->command('cleanup:redis --clear-locks')->daily();
|
2026-04-20 14:28:38 +02:00
|
|
|
$this->scheduleInstance->command('sanctum:prune-expired --hours=1')->hourly()->onOneServer();
|
|
|
|
|
$this->scheduleInstance->job(new ApiTokenExpirationWarningJob)->hourly()->onOneServer();
|
2024-09-08 19:37:00 +02:00
|
|
|
|
2023-08-27 15:23:47 +02:00
|
|
|
if (isDev()) {
|
2023-10-26 11:38:37 +02:00
|
|
|
// Instance Jobs
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->scheduleInstance->command('horizon:snapshot')->everyMinute();
|
|
|
|
|
$this->scheduleInstance->job(new CleanupInstanceStuffsJob)->everyMinute()->onOneServer();
|
|
|
|
|
$this->scheduleInstance->job(new CheckHelperImageJob)->everyTenMinutes()->onOneServer();
|
2024-11-03 09:02:14 +01:00
|
|
|
|
2023-10-26 11:38:37 +02:00
|
|
|
// Server Jobs
|
2025-08-22 11:50:56 +02:00
|
|
|
$this->scheduleInstance->job(new ServerManagerJob)->everyMinute()->onOneServer();
|
2024-11-03 09:02:14 +01:00
|
|
|
|
2025-07-12 14:44:52 +02:00
|
|
|
// Scheduled Jobs (Backups & Tasks)
|
|
|
|
|
$this->scheduleInstance->job(new ScheduledJobManager)->everyMinute()->onOneServer();
|
2024-11-03 09:02:14 +01:00
|
|
|
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->scheduleInstance->command('uploads:clear')->everyTwoMinutes();
|
2024-09-08 19:37:00 +02:00
|
|
|
|
2023-06-06 08:43:01 +02:00
|
|
|
} else {
|
2023-10-26 11:38:37 +02:00
|
|
|
// Instance Jobs
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->scheduleInstance->command('horizon:snapshot')->everyFiveMinutes();
|
|
|
|
|
$this->scheduleInstance->command('cleanup:unreachable-servers')->daily()->onOneServer();
|
|
|
|
|
|
|
|
|
|
$this->scheduleInstance->job(new PullTemplatesFromCDN)->cron($this->updateCheckFrequency)->timezone($this->instanceTimezone)->onOneServer();
|
2025-09-01 16:13:55 +02:00
|
|
|
$this->scheduleInstance->job(new PullChangelog)->cron($this->updateCheckFrequency)->timezone($this->instanceTimezone)->onOneServer();
|
2024-11-14 10:56:56 +01:00
|
|
|
|
|
|
|
|
$this->scheduleInstance->job(new CleanupInstanceStuffsJob)->everyTwoMinutes()->onOneServer();
|
|
|
|
|
$this->scheduleUpdates();
|
2023-10-26 11:38:37 +02:00
|
|
|
|
|
|
|
|
// Server Jobs
|
2025-08-22 11:50:56 +02:00
|
|
|
$this->scheduleInstance->job(new ServerManagerJob)->everyMinute()->onOneServer();
|
2024-11-03 09:02:14 +01:00
|
|
|
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->pullImages();
|
2024-11-03 09:02:14 +01:00
|
|
|
|
2025-07-12 14:44:52 +02:00
|
|
|
// Scheduled Jobs (Backups & Tasks)
|
|
|
|
|
$this->scheduleInstance->job(new ScheduledJobManager)->everyMinute()->onOneServer();
|
2024-03-04 12:17:33 +01:00
|
|
|
|
2026-05-21 19:19:43 +02:00
|
|
|
$this->scheduleInstance->job(new RegenerateSslCertJob)->twiceDaily()->onOneServer();
|
2025-02-05 22:11:10 +01:00
|
|
|
|
2025-11-13 13:38:57 +01:00
|
|
|
$this->scheduleInstance->job(new CheckTraefikVersionJob)->weekly()->sundays()->at('00:00')->timezone($this->instanceTimezone)->onOneServer();
|
|
|
|
|
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->scheduleInstance->command('cleanup:database --yes')->daily();
|
|
|
|
|
$this->scheduleInstance->command('uploads:clear')->everyTwoMinutes();
|
2025-12-08 17:15:52 +01:00
|
|
|
|
|
|
|
|
// Cleanup orphaned PR preview containers daily
|
|
|
|
|
$this->scheduleInstance->job(new CleanupOrphanedPreviewContainersJob)->daily()->onOneServer();
|
2023-10-26 11:38:37 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2024-11-14 10:56:56 +01:00
|
|
|
private function pullImages(): void
|
2023-10-26 11:38:37 +02:00
|
|
|
{
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->scheduleInstance->job(new CheckHelperImageJob)
|
2024-11-06 15:16:12 +01:00
|
|
|
->cron($this->updateCheckFrequency)
|
|
|
|
|
->timezone($this->instanceTimezone)
|
2024-09-19 11:24:21 +02:00
|
|
|
->onOneServer();
|
2024-08-05 16:31:41 +02:00
|
|
|
}
|
|
|
|
|
|
2024-11-14 10:56:56 +01:00
|
|
|
private function scheduleUpdates(): void
|
2024-08-05 16:31:41 +02:00
|
|
|
{
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->scheduleInstance->job(new CheckForUpdatesJob)
|
2024-11-06 15:16:12 +01:00
|
|
|
->cron($this->updateCheckFrequency)
|
|
|
|
|
->timezone($this->instanceTimezone)
|
2024-08-16 16:01:41 +02:00
|
|
|
->onOneServer();
|
2024-08-05 16:31:41 +02:00
|
|
|
|
2024-11-02 12:38:22 +01:00
|
|
|
if ($this->settings->is_auto_update_enabled) {
|
|
|
|
|
$autoUpdateFrequency = $this->settings->auto_update_frequency;
|
2024-11-14 10:56:56 +01:00
|
|
|
$this->scheduleInstance->job(new UpdateCoolifyJob)
|
2024-08-16 16:01:41 +02:00
|
|
|
->cron($autoUpdateFrequency)
|
2024-11-06 15:16:12 +01:00
|
|
|
->timezone($this->instanceTimezone)
|
2024-08-16 16:01:41 +02:00
|
|
|
->onOneServer();
|
2023-09-29 14:26:42 +02:00
|
|
|
}
|
|
|
|
|
}
|
2024-06-10 20:43:34 +00:00
|
|
|
|
2023-03-17 15:33:48 +01:00
|
|
|
protected function commands(): void
|
|
|
|
|
{
|
2024-08-26 15:26:08 +02:00
|
|
|
$this->load(__DIR__.'/Commands');
|
2023-03-17 15:33:48 +01:00
|
|
|
|
|
|
|
|
require base_path('routes/console.php');
|
|
|
|
|
}
|
2024-08-26 15:26:08 +02:00
|
|
|
}
|