Skip to content

Commit ccf238b

Browse files
author
Till Brehm
committed
Merge branch 'stable-3.1' into 'stable-3.1'
#5189 Warn if the lockfile for system cron is older than a day See merge request ispconfig/ispconfig3!843
2 parents 72aeccc + e7f95db commit ccf238b

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

server/cron.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,18 @@
3232
require SCRIPT_PATH."/lib/config.inc.php";
3333

3434
// Check whether another instance of this script is already running
35-
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')) {
35+
$lockFile = $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock';
36+
if (is_file($lockFile)) {
3637
clearstatcache();
37-
$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock'));
38+
39+
// Maybe we hit a deadlock and the lock file is no longer relevant
40+
if(filemtime($lockFile) > time() - 86400) { // 86400 seconds = 1 day
41+
if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - The cron lock file is older than one day.' . "\n";
42+
exit;
43+
}
44+
45+
// Check if the process id we have in the lock file is still present
46+
$pid = trim(file_get_contents($lockFile));
3847
if(preg_match('/^[0-9]+$/', $pid)) {
3948
if(file_exists('/proc/' . $pid)) {
4049
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 @@
4554
}
4655

4756
// Set Lockfile
48-
@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', getmypid());
57+
@file_put_contents($lockFile, getmypid());
4958

5059
if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock' . "\n";
5160

0 commit comments

Comments
 (0)