diff --git a/application/clicommands/JobsCommand.php b/application/clicommands/JobsCommand.php index 7272e5a4..04ce9da0 100644 --- a/application/clicommands/JobsCommand.php +++ b/application/clicommands/JobsCommand.php @@ -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; @@ -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( diff --git a/library/X509/Common/Database.php b/library/X509/Common/Database.php index a56920c5..57711fef 100644 --- a/library/X509/Common/Database.php +++ b/library/X509/Common/Database.php @@ -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]; diff --git a/library/X509/Common/JobOptions.php b/library/X509/Common/JobOptions.php index c9bf490a..bae3712f 100644 --- a/library/X509/Common/JobOptions.php +++ b/library/X509/Common/JobOptions.php @@ -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;