Skip to content
Snippets Groups Projects
Verified Commit e7f95dbe authored by Kordian Bruck's avatar Kordian Bruck
Browse files

Warn if the lockfile for system cron is older than a day

We want to avoid deadlock situations and right now if there is a process
running with the same PID that is not our process (e.g. after a reboot)
we might be waiting forever to run the cron again. So to make this
transparent to the user, we at least post a warning into the logfile.
parent 72aeccc6
No related branches found
No related tags found
2 merge requests!860Stable 3.1,!843#5189 Warn if the lockfile for system cron is older than a day
...@@ -32,9 +32,18 @@ define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"])); ...@@ -32,9 +32,18 @@ define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"]));
require SCRIPT_PATH."/lib/config.inc.php"; require SCRIPT_PATH."/lib/config.inc.php";
// Check whether another instance of this script is already running // Check whether another instance of this script is already running
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')) { $lockFile = $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock';
if (is_file($lockFile)) {
clearstatcache(); clearstatcache();
$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock'));
// Maybe we hit a deadlock and the lock file is no longer relevant
if(filemtime($lockFile) > time() - 86400) { // 86400 seconds = 1 day
if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - The cron lock file is older than one day.' . "\n";
exit;
}
// Check if the process id we have in the lock file is still present
$pid = trim(file_get_contents($lockFile));
if(preg_match('/^[0-9]+$/', $pid)) { if(preg_match('/^[0-9]+$/', $pid)) {
if(file_exists('/proc/' . $pid)) { if(file_exists('/proc/' . $pid)) {
if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is already an instance of server.php running with pid ' . $pid . '.' . "\n"; if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is already an instance of server.php running with pid ' . $pid . '.' . "\n";
...@@ -45,7 +54,7 @@ if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')) { ...@@ -45,7 +54,7 @@ if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')) {
} }
// Set Lockfile // Set Lockfile
@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', getmypid()); @file_put_contents($lockFile, getmypid());
if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock' . "\n"; if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock' . "\n";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment