Commit 1706e8bd authored by Franco Fichtner's avatar Franco Fichtner

gateways: always restart apinger, HUP doesn't work

(cherry picked from commit 5d60cd1f)
parent ea0da8c2
...@@ -42,20 +42,13 @@ function return_apinger_defaults() ...@@ -42,20 +42,13 @@ function return_apinger_defaults()
); );
} }
function setup_gateways_monitor_full()
{
killbypid('/var/run/apinger.pid');
setup_gateways_monitor();
}
/*
* Creates monitoring configuration file and
* adds appropriate static routes.
*/
function setup_gateways_monitor() function setup_gateways_monitor()
{ {
global $config; global $config;
killbypid('/var/run/apinger.pid', 'TERM', true);
@unlink('/var/run/apinger.status');
@mkdir('/var/db/rrd', 0775); @mkdir('/var/db/rrd', 0775);
@chown('/var/db/rrd', 'nobody'); @chown('/var/db/rrd', 'nobody');
...@@ -380,27 +373,11 @@ EOD; ...@@ -380,27 +373,11 @@ EOD;
$gateways_arr = return_gateways_array(); $gateways_arr = return_gateways_array();
if (!is_array($gateways_arr)) { if (!is_array($gateways_arr)) {
log_error("No gateways to monitor. Apinger will not be run."); log_error("No gateways to monitor. Apinger will not be run.");
killbypid('/var/run/apinger.pid');
@unlink('/var/run/apinger.status');
return; return;
} }
@file_put_contents('/var/etc/apinger.conf', $apingerconfig); file_put_contents('/var/etc/apinger.conf', $apingerconfig);
unset($apingerconfig); mwexec_bg('/usr/local/sbin/apinger -c /var/etc/apinger.conf');
/* Restart apinger process */
if (isvalidpid('/var/run/apinger.pid')) {
killbypid('/var/run/apinger.pid', 'HUP');
} else {
/* start a new apinger process */
@unlink('/var/run/apinger.status');
sleep(1);
mwexec_bg('/usr/local/sbin/apinger -c /var/etc/apinger.conf');
sleep(1);
killbypid('/var/run/apinger.pid', 'USR1');
}
return 0;
} }
/* return the status of the apinger targets as a array */ /* return the status of the apinger targets as a array */
...@@ -412,6 +389,7 @@ function return_gateways_status($byname = false) ...@@ -412,6 +389,7 @@ function return_gateways_status($byname = false)
/* Always get the latest status from apinger */ /* Always get the latest status from apinger */
killbypid('/var/run/apinger.pid', 'USR1'); killbypid('/var/run/apinger.pid', 'USR1');
/* we may read the wrong file here as it's async: */
if (file_exists('/var/run/apinger.status')) { if (file_exists('/var/run/apinger.status')) {
$apingerstatus = file('/var/run/apinger.status'); $apingerstatus = file('/var/run/apinger.status');
} }
......
...@@ -2541,7 +2541,7 @@ function services_get() ...@@ -2541,7 +2541,7 @@ function services_get()
$pconfig = array(); $pconfig = array();
$pconfig['name'] = "apinger"; $pconfig['name'] = "apinger";
$pconfig['description'] = gettext("Gateway Monitoring Daemon"); $pconfig['description'] = gettext("Gateway Monitoring Daemon");
$pconfig['php']['restart'] = array('setup_gateways_monitor_full'); $pconfig['php']['restart'] = array('setup_gateways_monitor');
$pconfig['php']['start'] = array('setup_gateways_monitor'); $pconfig['php']['start'] = array('setup_gateways_monitor');
$pconfig['pidfile'] = '/var/run/apinger.pid'; $pconfig['pidfile'] = '/var/run/apinger.pid';
$services[] = $pconfig; $services[] = $pconfig;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment