From 3cc04cc5219bfd72d83b58d2f6ae83092e0c9fb6 Mon Sep 17 00:00:00 2001
From: Marius Burkard <m.burkard@pixcept.de>
Date: Tue, 05 Jul 2016 07:14:13 -0400
Subject: [PATCH] Merge branch 'stable-3.1' into 'stable-3.1'

---
 server/cron.php |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/server/cron.php b/server/cron.php
index 7a43d04..58d48ec 100644
--- a/server/cron.php
+++ b/server/cron.php
@@ -30,6 +30,26 @@
 
 define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"]));
 require SCRIPT_PATH."/lib/config.inc.php";
+
+// Check whether another instance of this script is already running
+if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')) {
+	clearstatcache();
+	$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock'));
+	if(preg_match('/^[0-9]+$/', $pid)) {
+		if(file_exists('/proc/' . $pid)) {
+			print @date('d.m.Y-H:i').' - WARNING - There is already an instance of server.php running with pid ' . $pid . '.' . "\n";
+			exit;
+		}
+	}
+	print @date('d.m.Y-H:i').' - WARNING - There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.' . "\n";
+}
+
+// Set Lockfile
+@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', getmypid());
+
+if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock' . "\n";
+
+
 require SCRIPT_PATH."/lib/app.inc.php";
 
 set_time_limit(0);
@@ -74,7 +94,7 @@
 			unset($cronjob);
 			continue;
 		}
-		print 'Included ' . $class_name . ' from ' . $file_path . ' -> will now run job.' . "\n";
+		print 'Included ' . $class_name . ' from ' . $path . '/' . $f . ' -> will now run job.' . "\n";
 
 		$cronjob->run();
 
@@ -85,6 +105,10 @@
 }
 unset($files);
 
+// Remove lock
+@unlink($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock');
+$app->log('Remove Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', LOGLEVEL_DEBUG);
+
 die("finished.\n");
 
 ?>

--
Gitblit v1.9.1