Skip to content

Commit

Permalink
Merge pull request #215 from Icinga/fix-daemon-crashes-with-fullscan
Browse files Browse the repository at this point in the history
Prevent from crashing the daemon
  • Loading branch information
yhabteab authored Oct 27, 2023
2 parents 3f36297 + e59d22c commit 9f59918
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
17 changes: 16 additions & 1 deletion application/clicommands/JobsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@

use DateTime;
use Exception;
use Icinga\Application\Config;
use Icinga\Application\Logger;
use Icinga\Data\ResourceFactory;
use Icinga\Module\X509\CertificateUtils;
use Icinga\Module\X509\Command;
use Icinga\Module\X509\Common\JobUtils;
Expand Down Expand Up @@ -81,7 +83,20 @@ public function runAction(): void
// Periodically check configuration changes to ensure that new jobs are scheduled, jobs are updated,
// and deleted jobs are canceled.
$watchdog = function () use (&$watchdog, &$scheduled, $scheduler, $parallel, $jobName, $scheduleName) {
$jobs = $this->fetchSchedules($jobName, $scheduleName);
$jobs = [];
try {
// Since this is a long-running daemon, the resources or module config may change meanwhile.
// Therefore, reload the resources and module config from disk each time (at 5m intervals)
// before reconnecting to the database.
ResourceFactory::setConfig(Config::app('resources', true));
Config::module('x509', 'config', true);

$jobs = $this->fetchSchedules($jobName, $scheduleName);
} catch (Throwable $err) {
Logger::error('Failed to fetch job schedules from the database: %s', $err);
Logger::debug($err->getTraceAsString());
}

$outdatedJobs = array_diff_key($scheduled, $jobs);
foreach ($outdatedJobs as $job) {
Logger::info(
Expand Down
2 changes: 1 addition & 1 deletion library/X509/Common/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ trait Database
protected function getDb(): Sql\Connection
{
$config = new Sql\Config(ResourceFactory::getResourceConfig(
Config::module('x509')->get('backend', 'resource')
Config::module('x509')->get('backend', 'resource', 'x509')
));

$options = [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ];
Expand Down
4 changes: 2 additions & 2 deletions library/X509/Common/JobOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public function setSchedule(Schedule $schedule): self

/** @var stdClass $config */
$config = $schedule->getConfig();
$this->setRescan($config->rescan);
$this->setFullScan($config->full_scan);
$this->setFullScan($config->full_scan ?? false);
$this->setRescan($config->rescan ?? false);
$this->setLastScan($config->since_last_scan ?? Job::DEFAULT_SINCE_LAST_SCAN);

return $this;
Expand Down

0 comments on commit 9f59918

Please sign in to comment.