2015-12-06 18:58:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Console;
|
|
|
|
|
2022-11-22 20:39:43 +00:00
|
|
|
use Ramsey\Uuid\Uuid;
|
2022-05-29 23:45:00 +00:00
|
|
|
use Pterodactyl\Models\ActivityLog;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Illuminate\Console\Scheduling\Schedule;
|
2022-05-29 23:45:00 +00:00
|
|
|
use Illuminate\Database\Console\PruneCommand;
|
2022-11-22 20:39:43 +00:00
|
|
|
use Pterodactyl\Repositories\Eloquent\SettingsRepository;
|
2015-12-06 18:58:49 +00:00
|
|
|
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
2022-11-22 20:39:43 +00:00
|
|
|
use Pterodactyl\Services\Telemetry\TelemetryCollectionService;
|
2022-05-29 23:45:00 +00:00
|
|
|
use Pterodactyl\Console\Commands\Schedule\ProcessRunnableCommand;
|
|
|
|
use Pterodactyl\Console\Commands\Maintenance\PruneOrphanedBackupsCommand;
|
|
|
|
use Pterodactyl\Console\Commands\Maintenance\CleanServiceBackupFilesCommand;
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
class Kernel extends ConsoleKernel
|
|
|
|
{
|
|
|
|
/**
|
2017-12-17 19:07:38 +00:00
|
|
|
* Register the commands for the application.
|
2015-12-06 18:58:49 +00:00
|
|
|
*/
|
2023-02-23 19:30:16 +00:00
|
|
|
protected function commands(): void
|
2017-12-17 19:07:38 +00:00
|
|
|
{
|
|
|
|
$this->load(__DIR__ . '/Commands');
|
|
|
|
}
|
2015-12-06 18:58:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Define the application's command schedule.
|
|
|
|
*/
|
2023-02-23 19:30:16 +00:00
|
|
|
protected function schedule(Schedule $schedule): void
|
2015-12-06 18:58:49 +00:00
|
|
|
{
|
2023-02-23 19:30:16 +00:00
|
|
|
// https://laravel.com/docs/10.x/upgrade#redis-cache-tags
|
|
|
|
$schedule->command('cache:prune-stale-tags')->hourly();
|
|
|
|
|
2020-08-21 03:48:08 +00:00
|
|
|
// Execute scheduled commands for servers every minute, as if there was a normal cron running.
|
2022-05-29 23:45:00 +00:00
|
|
|
$schedule->command(ProcessRunnableCommand::class)->everyMinute()->withoutOverlapping();
|
|
|
|
$schedule->command(CleanServiceBackupFilesCommand::class)->daily();
|
2020-08-21 03:48:08 +00:00
|
|
|
|
2021-01-23 22:12:15 +00:00
|
|
|
if (config('backups.prune_age')) {
|
|
|
|
// Every 30 minutes, run the backup pruning command so that any abandoned backups can be deleted.
|
2022-05-29 23:45:00 +00:00
|
|
|
$schedule->command(PruneOrphanedBackupsCommand::class)->everyThirtyMinutes();
|
2020-12-16 21:15:07 +00:00
|
|
|
}
|
2020-08-21 03:48:08 +00:00
|
|
|
|
2022-05-29 23:45:00 +00:00
|
|
|
if (config('activity.prune_days')) {
|
|
|
|
$schedule->command(PruneCommand::class, ['--model' => [ActivityLog::class]])->daily();
|
|
|
|
}
|
2022-11-22 20:39:43 +00:00
|
|
|
|
|
|
|
if (config('pterodactyl.telemetry.enabled')) {
|
|
|
|
$this->registerTelemetry($schedule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* I wonder what this does.
|
|
|
|
*
|
|
|
|
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
|
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
|
|
|
*/
|
|
|
|
private function registerTelemetry(Schedule $schedule): void
|
|
|
|
{
|
|
|
|
$settingsRepository = app()->make(SettingsRepository::class);
|
|
|
|
|
2022-12-04 21:59:45 +00:00
|
|
|
$uuid = $settingsRepository->get('app:telemetry:uuid');
|
2022-11-22 20:39:43 +00:00
|
|
|
if (is_null($uuid)) {
|
|
|
|
$uuid = Uuid::uuid4()->toString();
|
2022-12-04 21:59:45 +00:00
|
|
|
$settingsRepository->set('app:telemetry:uuid', $uuid);
|
2022-11-22 20:39:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate a fixed time to run the data push at, this will be the same time every day.
|
|
|
|
$time = hexdec(str_replace('-', '', substr($uuid, 27))) % 1440;
|
|
|
|
$hour = floor($time / 60);
|
|
|
|
$minute = $time % 60;
|
|
|
|
|
|
|
|
// Run the telemetry collector.
|
|
|
|
$schedule->call(app()->make(TelemetryCollectionService::class))->description('Collect Telemetry')->dailyAt("$hour:$minute");
|
2015-12-06 18:58:49 +00:00
|
|
|
}
|
|
|
|
}
|