From fdf46f317c34b70398a6dcb9487fe141bcfd55f9 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Sat, 3 Jun 2023 09:26:55 +0200 Subject: [PATCH] system: improve RRD collector PID/service handling PR: https://forum.opnsense.org/index.php?topic=34241.0 --- src/etc/inc/rrd.inc | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/src/etc/inc/rrd.inc b/src/etc/inc/rrd.inc index 1ba8581bf..ede6aa5b4 100644 --- a/src/etc/inc/rrd.inc +++ b/src/etc/inc/rrd.inc @@ -100,6 +100,9 @@ function rrd_configure($verbose = false, $bootup = false) $downstream = 2500000000; $upstream = 2500000000; + /* kill off traffic collectors */ + killbypid('/var/run/updaterrd.pid'); + if (isset($config['rrd']['enable'])) { /* create directory if needed */ if (!is_dir($rrddbpath)) { @@ -112,8 +115,6 @@ function rrd_configure($verbose = false, $bootup = false) $rrdupdatesh .= "\n"; $rrdupdatesh .= "export TERM=dumb\n"; $rrdupdatesh .= "\n"; - $rrdupdatesh .= 'echo $$ > /var/run/updaterrd.sh.pid'; - $rrdupdatesh .= "\n"; $rrdupdatesh .= "counter=1\n"; $rrdupdatesh .= "while [ \"\$counter\" -ne 0 ]\n"; $rrdupdatesh .= "do\n"; @@ -560,17 +561,10 @@ EOD; $fd = fopen("$updaterrdscript", "w"); fwrite($fd, "$rrdupdatesh"); fclose($fd); - - unset($rrdupdatesh); - - /* kill off traffic collectors */ - rrd_stop(); + chmod($updaterrdscrip, 0755); /* start traffic collector */ - mwexec_bg("/bin/sh $updaterrdscript"); - } else { - /* kill off traffic collectors */ - rrd_stop(); + mwexecf('/usr/sbin/daemon -f -p %s %s', ['/var/run/updaterrd.pid', $updaterrdscript]); } $databases = glob("{$rrddbpath}/*.rrd"); @@ -609,11 +603,6 @@ function rrd_create_gateway_quality($rrd_file, $unknown = false) } } -function rrd_stop() -{ - killbypid('/var/run/updaterrd.sh.pid'); -} - function rrd_export() { $rrddbpath = '/var/db/rrd';