Files

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

93 lines
2.5 KiB
PHP
Raw Permalink Normal View History

2018-05-09 08:05:17 -05:00
<?php
namespace App\Console;
2023-08-03 19:29:30 -05:00
use App\Console\Commands\MaintenanceFetchOuis;
2018-05-09 08:05:17 -05:00
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Illuminate\Support\Facades\Cache;
2023-08-03 19:29:30 -05:00
use LibreNMS\Config;
2021-04-29 22:42:18 -05:00
use LibreNMS\Util\Debug;
2019-01-08 21:42:56 -06:00
use LibreNMS\Util\Version;
2018-05-09 08:05:17 -05:00
class Kernel extends ConsoleKernel
{
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @return void
*/
2023-05-24 22:21:54 +02:00
protected function schedule(Schedule $schedule): void
2018-05-09 08:05:17 -05:00
{
$this->scheduleMarkWorking($schedule);
2023-08-03 19:29:30 -05:00
$this->scheduleMaintenance($schedule); // should be after all others
2018-05-09 08:05:17 -05:00
}
/**
* Register the commands for the application.
2018-05-09 08:05:17 -05:00
*
* @return void
*/
2023-05-24 22:21:54 +02:00
protected function commands(): void
2018-05-09 08:05:17 -05:00
{
$this->load(__DIR__ . '/Commands');
2018-05-09 08:05:17 -05:00
require base_path('routes/console.php');
2019-01-08 21:42:56 -06:00
if ($this->app->environment() !== 'production') {
require base_path('routes/dev-console.php');
}
}
2019-01-28 08:45:47 -06:00
public function getArtisan()
2019-01-08 21:42:56 -06:00
{
if (is_null($this->artisan)) {
parent::getArtisan();
2021-03-24 15:13:43 +01:00
/** @phpstan-ignore-next-line */
2022-09-18 06:44:45 +02:00
$this->artisan->setName('LibreNMS');
2021-03-24 15:13:43 +01:00
/** @phpstan-ignore-next-line */
2022-09-18 06:44:45 +02:00
$this->artisan->setVersion(Version::VERSION);
2019-01-08 21:42:56 -06:00
}
return $this->artisan;
2018-05-09 08:05:17 -05:00
}
2019-01-09 19:36:32 -06:00
public function handle($input, $output = null)
{
// intercept input and check for debug
if ($input->hasParameterOption(['-d', '--debug', '-vv', '-vvv'], true)) {
if ($input->hasParameterOption(['-vvv'], true)) {
2021-04-29 22:42:18 -05:00
Debug::setVerbose();
2019-01-09 19:36:32 -06:00
}
2021-04-29 22:42:18 -05:00
$this->app->booted('\LibreNMS\Util\Debug::set');
2019-01-09 19:36:32 -06:00
}
return parent::handle($input, $output);
}
/**
* Store in the cache that the schedule is triggered.
* Used for Validation.
*/
private function scheduleMarkWorking(Schedule $schedule): void
{
$schedule->call(function () {
Cache::put('scheduler_working', now(), now()->addMinutes(6));
})->everyFiveMinutes();
}
2023-08-03 19:29:30 -05:00
/**
* Schedule maintenance tasks
*/
private function scheduleMaintenance(Schedule $schedule): void
{
$maintenance_log_file = Config::get('log_dir') . '/maintenance.log';
$schedule->command(MaintenanceFetchOuis::class, ['--wait'])
->weeklyOn(0, '1:00')
->onOneServer()
->appendOutputTo($maintenance_log_file);
}
2018-05-09 08:05:17 -05:00
}