diff --git a/include/cronhooks.php b/include/cronhooks.php index d5daf0d7d4..0ba453555c 100644 --- a/include/cronhooks.php +++ b/include/cronhooks.php @@ -37,9 +37,15 @@ function cronhooks_run(&$argv, &$argc){ $lockpath = get_config('system','lockpath'); if ($lockpath != '') { - $pidfile = new pidfile($lockpath, 'cron.lck'); + $pidfile = new pidfile($lockpath, 'cronhooks'); if($pidfile->is_already_running()) { logger("cronhooks: Already running"); + if ($pidfile->running_time() > 9*60) { + $pidfile->kill(); + logger("cronhooks: killed stale process"); + // Calling a new instance + proc_run('php','include/cronhooks.php'); + } exit; } } @@ -52,8 +58,6 @@ function cronhooks_run(&$argv, &$argc){ $d = datetime_convert(); - set_time_limit(9*60*60); // Setting the maximum execution time for cronjobs to 9 minutes. - call_hooks('cron', $d); logger('cronhooks: end'); diff --git a/include/onepoll.php b/include/onepoll.php index 49047118a4..15b8e7c2cc 100644 --- a/include/onepoll.php +++ b/include/onepoll.php @@ -60,7 +60,7 @@ function onepoll_run(&$argv, &$argc){ // Test $lockpath = get_config('system','lockpath'); if ($lockpath != '') { - $pidfile = new pidfile($lockpath, 'onepoll'.$contact_id.'.lck'); + $pidfile = new pidfile($lockpath, 'onepoll'.$contact_id); if($pidfile->is_already_running()) { logger("onepoll: Already running for contact ".$contact_id); exit; diff --git a/include/pidfile.php b/include/pidfile.php index 47df8d1f46..4f5b25ad75 100644 --- a/include/pidfile.php +++ b/include/pidfile.php @@ -28,5 +28,14 @@ class pidfile { public function is_already_running() { return $this->_running; } + + public function running_time() { + return(time() - filectime($this->_file)); + } + + public function kill() { + if (file_exists($this->_file)) + return(posix_kill(file_get_contents($this->_file), SIGTERM)); + } } ?> diff --git a/include/poller.php b/include/poller.php index 084067b190..b04c77f744 100644 --- a/include/poller.php +++ b/include/poller.php @@ -43,9 +43,15 @@ function poller_run(&$argv, &$argc){ $lockpath = get_config('system','lockpath'); if ($lockpath != '') { - $pidfile = new pidfile($lockpath, 'poller.lck'); + $pidfile = new pidfile($lockpath, 'poller'); if($pidfile->is_already_running()) { logger("poller: Already running"); + if ($pidfile->running_time() > 9*60) { + $pidfile->kill(); + logger("poller: killed stale process"); + // Calling a new instance + proc_run('php','include/poller.php'); + } exit; } } diff --git a/include/queue.php b/include/queue.php index 7fb6c6d90a..bc3cc258cc 100644 --- a/include/queue.php +++ b/include/queue.php @@ -86,9 +86,15 @@ function queue_run(&$argv, &$argc){ $lockpath = get_config('system','lockpath'); if ($lockpath != '') { - $pidfile = new pidfile($lockpath, 'queue.lck'); + $pidfile = new pidfile($lockpath, 'queue'); if($pidfile->is_already_running()) { logger("queue: Already running"); + if ($pidfile->running_time() > 9*60) { + $pidfile->kill(); + logger("queue: killed stale process"); + // Calling a new instance + proc_run('php',"include/queue.php"); + } return; } } @@ -106,8 +112,6 @@ function queue_run(&$argv, &$argc){ logger('queue: start'); - set_time_limit(9*60*60); // Setting the maximum execution time for queue job to 9 minutes. - handle_pubsubhubbub(); $interval = ((get_config('system','delivery_interval') === false) ? 2 : intval(get_config('system','delivery_interval')));