diff --git a/alerts.php b/alerts.php index af7c83506..878c23e32 100755 --- a/alerts.php +++ b/alerts.php @@ -25,11 +25,29 @@ include("includes/defaults.inc.php"); include("config.php"); + +$lock = false; +if( file_exists($config['install_dir']."/.alerts.lock") ) { + $pids = explode("\n", trim(`ps -e | grep php | awk '{print $1}'`)); + $lpid = trim(file_get_contents($config['install_dir']."/.alerts.lock")); + if( in_array($lpid,$pids) ) { + $lock = true; + } +} + +if( $lock === true ) { + exit('Alreading running with PID '.$lpid."\r\n"); +} else { + file_put_contents($config['install_dir']."/.alerts.lock", getmypid()); +} + include("includes/definitions.inc.php"); include("includes/functions.php"); RunAlerts(); +unlink($config['install_dir']."/.alerts.lock"); + /** * Run all alerts * @return void diff --git a/librenms.cron b/librenms.cron index f2171210f..49f74898d 100644 --- a/librenms.cron +++ b/librenms.cron @@ -2,4 +2,4 @@ */5 * * * * root /opt/librenms/discovery.php -h new >> /dev/null 2>&1 */5 * * * * root /opt/librenms/poller-wrapper.py 16 >> /dev/null 2>&1 15 0 * * * root sh /opt/librenms/daily.sh >> /dev/null 2>&1 -*/2 * * * * root /opt/librenms/alerts.php >> /dev/null 2>&1 +* * * * * root /opt/librenms/alerts.php >> /dev/null 2>&1