Skip to content

Commit 13a5474

Browse files
author
Marius Burkard
committed
- fixed cron lockfile check, fixes #5334
1 parent c8b6f25 commit 13a5474

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

server/cron.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,28 @@
3333

3434
// Check whether another instance of this script is already running
3535
$lockFile = $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock';
36-
if (is_file($lockFile)) {
36+
if(is_file($lockFile)) {
3737
clearstatcache();
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
38+
39+
// Check if the process id we have in the lock file is still present
4640
$pid = trim(file_get_contents($lockFile));
4741
if(preg_match('/^[0-9]+$/', $pid)) {
48-
if(file_exists('/proc/' . $pid)) {
49-
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";
50-
exit;
42+
if(is_dir('/proc/' . $pid)) {
43+
if(file_exists('/proc/' . $pid . '/cmdline')) {
44+
if(strpos(file_get_contents('/proc/' . $pid . '/cmdline'), 'cron.php') !== false) {
45+
if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is already an instance of cron.php running with pid ' . $pid . '.' . "\n";
46+
exit;
47+
} else {
48+
if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is a process running with pid ' . $pid . ' but it seems not to be cron.php, continuing.' . "\n";
49+
}
50+
} else {
51+
if(filemtime($lockFile) < time() - 86400) {
52+
if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is already an instance of cron.php running with pid ' . $pid . ' but process is older than 1 day. Continuing.' . "\n";
53+
} else {
54+
if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is already an instance of cron.php running with pid ' . $pid . '.' . "\n";
55+
exit;
56+
}
57+
}
5158
}
5259
}
5360
if($conf['log_priority'] <= LOGLEVEL_WARN) print @date('d.m.Y-H:i').' - WARNING - There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.' . "\n";

0 commit comments

Comments
 (0)