]> git.mxchange.org Git - friendica.git/commitdiff
Dead processes will be deleted when they are running for more than 9 minutes.
authorMichael Vogel <icarus@dabo.de>
Wed, 21 May 2014 22:16:36 +0000 (00:16 +0200)
committerMichael Vogel <icarus@dabo.de>
Wed, 21 May 2014 22:16:36 +0000 (00:16 +0200)
include/cronhooks.php
include/onepoll.php
include/pidfile.php
include/poller.php
include/queue.php

index d5daf0d7d447a2beb4bb7a769872dd3b410b6dbf..0ba453555ce63c580622d922ed3feee27438e329 100644 (file)
@@ -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');
index 49047118a4b20c3fe96b3a255518657cd0c85de2..15b8e7c2cc20c2679f04cfe2e1408585aed071a4 100644 (file)
@@ -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;
index 47df8d1f4624ef43fa2430d013f4000f8edad411..4f5b25ad756521af2dee7626a26beb6c83395964 100644 (file)
@@ -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));
+       }
 }
 ?>
index 084067b190059c3c6f0290b2476811b1f2c87d82..b04c77f74446d80ce627fb41786a50b9aae3ed49 100644 (file)
@@ -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;
                }
        }
index 7fb6c6d90a7f553ad593bd85e04f125b934b69e1..bc3cc258cc8c0ce04f56b038ebc1deb8161ee242 100644 (file)
@@ -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')));