Skip to content

Commit

Permalink
system: defer start of lighttpd on newwanip event #6351
Browse files Browse the repository at this point in the history
Looks like improvements in 23.1.4 made the problem worse, indicating
that the direction this is going is a bit doubtful.  Instead, funnel
the restart through configd to reach some state of serialization
similar to what filter_configure() is doing.

While here move the service definition to the correct file.
  • Loading branch information
fichtner committed Mar 22, 2023
1 parent bbbed94 commit 33ad504
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
10 changes: 0 additions & 10 deletions src/etc/inc/plugins.inc.d/core.inc
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,6 @@ function core_services()
'name' => 'syslog-ng',
);

$services[] = array(
'pidfile' => '/var/run/lighty-webConfigurator.pid',
'description' => gettext('Web GUI'),
'php' => array(
'restart' => array('webgui_configure_delayed')
),
'name' => 'webgui',
'locked' => true,
);

return $services;
}

Expand Down
42 changes: 31 additions & 11 deletions src/etc/inc/plugins.inc.d/webgui.inc
Original file line number Diff line number Diff line change
Expand Up @@ -30,37 +30,57 @@

function webgui_configure()
{
return array(
'early' => array('webgui_configure_do'),
'local' => array('webgui_configure_do'),
'newwanip' => array('webgui_configure_do:2'),
'webgui' => array('webgui_configure_do'),
);
return [
'early' => ['webgui_configure_do'],
'local' => ['webgui_configure_do'],
'newwanip' => ['webgui_configure_do:2'],
'webgui' => ['webgui_configure_do'],
];
}

function webgui_configure_delayed()
function webgui_services()
{
configd_run('webgui restart 3', true);
return [[
'pidfile' => '/var/run/lighty-webConfigurator.pid',
'description' => gettext('Web GUI'),
'php' => ['restart' => ['webgui_configure_defer']],
'name' => 'webgui',
'locked' => true,
]];
}

function webgui_configure_defer($verbose = false, $sleep = 3)
{
service_log('Starting web GUI...', $verbose);
configdp_run('webgui restart', [$sleep], true);
service_log("deferred.\n", $verbose);
}

function webgui_configure_do($verbose = false, $interface = '')
{
global $config;

$interfaces = array();
$interfaces = [];
if (!empty($config['system']['webgui']['interfaces'])) {
$interfaces = explode(',', $config['system']['webgui']['interfaces']);
/* place loopback with good IPv4 first for server.bind */
array_unshift($interfaces, 'lo0');
}

if (!empty($interface) && !in_array($interface, $interfaces)) {
/* 'newwanip' configuration is the only event to take second argument */
if (!empty($interface)) {
if (in_array($interface, $interfaces)) {
/* funnel through configd to avoid race conditions */
webgui_configure_defer($verbose, 0);
}

/* nothing else to do */
return;
}

service_log('Starting web GUI...', $verbose);

$listeners = count($interfaces) ? array() : array('0.0.0.0', '::');
$listeners = count($interfaces) ? [] : ['0.0.0.0', '::'];

foreach (interfaces_addresses($interfaces) as $tmpaddr => $info) {
if ($info['scope']) {
Expand Down

0 comments on commit 33ad504

Please sign in to comment.