dns/ddclient - prevent model usage in ddclient_services()

The ddclient model uses configd for additional info, which makes model initialization a bit slower than usual.
When only checking if the module is used, accessing the config object saves a lot of time.
This commit is contained in:
Ad Schellevis
2024-03-13 19:52:05 +01:00
parent 9999bf1472
commit 6fbc5137d3
2 changed files with 8 additions and 4 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
PLUGIN_NAME= ddclient
PLUGIN_VERSION= 1.21
PLUGIN_REVISION= 1
PLUGIN_REVISION= 2
PLUGIN_DEPENDS= ddclient py${PLUGIN_PYTHON}-boto3
PLUGIN_COMMENT= Dynamic DNS client
PLUGIN_MAINTAINER= ad@opnsense.org
@@ -30,9 +30,13 @@
function ddclient_services()
{
$services = [];
$cnf = \OPNsense\Core\Config::getInstance()->object();
$is_enabled = false;
if ($cnf->OPNsense && $cnf->OPNsense->DynDNS && $cnf->OPNsense->DynDNS->general){
$is_enabled = $cnf->OPNsense->DynDNS->general->enabled == '1';
}
$mdl = new \OPNsense\DynDNS\DynDNS();
if ($mdl->general->enabled == '1') {
if ($is_enabled) {
$service = [
'description' => gettext('ddclient'),
'configd' => [
@@ -42,7 +46,7 @@ function ddclient_services()
],
'name' => 'ddclient',
];
$service['pidfile'] = (string)$mdl->general->backend != 'opnsense' ? '/var/run/ddclient.pid' : '/var/run/ddclient_opn.pid';
$service['pidfile'] = $cnf->OPNsense->DynDNS->general->backend != 'opnsense' ? '/var/run/ddclient.pid' : '/var/run/ddclient_opn.pid';
$services[] = $service;
}