system: defer config reload to SIGHUP in gateway watcher

This should considerably lower CPU usage as reported a few times.
We do need to bring in pcntl PHP module in order to get that done
easily in the script.

PR: https://forum.opnsense.org/index.php?topic=35219.0
This commit is contained in:
Franco Fichtner 2023-08-24 09:58:22 +02:00
parent 6b90972371
commit b94097567c
3 changed files with 26 additions and 11 deletions

View File

@ -167,9 +167,10 @@ CORE_DEPENDS?= ca_root_nss \
php${CORE_PHP}-gettext \
php${CORE_PHP}-google-api-php-client \
php${CORE_PHP}-ldap \
php${CORE_PHP}-pcntl \
php${CORE_PHP}-pdo \
php${CORE_PHP}-pecl-radius \
php${CORE_PHP}-pear-Crypt_CHAP \
php${CORE_PHP}-pecl-radius \
php${CORE_PHP}-phalcon \
php${CORE_PHP}-phpseclib \
php${CORE_PHP}-session \

View File

@ -319,12 +319,17 @@ function dpinger_configure_do($verbose = false, $gwname = null, $bootup = false)
}
if (count(dpinger_services())) {
/* use a separate script to produce the monitor alerts which runs forever */
mwexecf(
'/usr/sbin/daemon -f -p %s /usr/local/opnsense/scripts/routes/gateway_watcher.php %s',
['/var/run/gateway_watcher.pid', 'interface routes alarm'],
true
);
if (isvalidpid('/var/run/gateway_watcher.pid')) {
/* indicate that the configuration needs a reload */
killbypid('/var/run/gateway_watcher.pid', 'HUP');
} else {
/* use a separate script to produce the monitor alerts which runs forever */
mwexecf(
'/usr/sbin/daemon -f -p %s /usr/local/opnsense/scripts/routes/gateway_watcher.php %s',
['/var/run/gateway_watcher.pid', 'interface routes alarm'],
true
);
}
} else {
killbypid('/var/run/gateway_watcher.pid');
}

View File

@ -31,7 +31,18 @@ require_once 'config.inc';
require_once 'util.inc';
require_once 'interfaces.inc';
function signalhandler($signal)
{
global $config;
OPNsense\Core\Config::getInstance()->forceReload();
$config = parse_config();
syslog(LOG_NOTICE, 'Reloaded gateway watcher configuration on SIGHUP');
}
openlog('dpinger', LOG_DAEMON, LOG_LOCAL4);
pcntl_signal(SIGHUP, 'signalhandler');
$action = !empty($argv[1]) ? $argv[1] : null;
@ -43,12 +54,10 @@ $mode = [];
sleep($wait);
while (1) {
$alarm = false;
OPNsense\Core\Config::getInstance()->forceReload();
$config = parse_config();
pcntl_signal_dispatch();
$status = return_gateways_status();
$alarm = false;
/* clear known gateways in first step to flush unknown in second step */
$cleanup = $mode;