Skip to content

Commit b18806e

Browse files
author
Marius Cramer
committed
Improved lock file to reduce risk of stale lock file without running process
1 parent 7e886ae commit b18806e

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

server/server.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,22 +128,18 @@
128128
// Check whether another instance of this script is already running
129129
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock')) {
130130
clearstatcache();
131-
for ($i = 0; $i < 120; $i++) { // Wait max. 1200 sec, then retry
132-
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock')) {
133-
exec("ps aux | grep '/usr/local/ispconfig/server/[s]erver.php' | wc -l", $check);
134-
if (intval($check[0]) > 1) { // 1 because this is 2nd instance!
135-
$app->log('There is already an instance of server.php running. Exiting.', LOGLEVEL_DEBUG);
136-
exit;
137-
}
138-
$app->log('There is already a lockfile set. Waiting another 10 seconds...', LOGLEVEL_DEBUG);
139-
sleep(10);
140-
clearstatcache();
131+
$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock'));
132+
if(preg_match('/^[0-9]+$/', $pid)) {
133+
if(file_exists('/proc/' . $pid)) {
134+
$app->log('There is already an instance of server.php running with pid ' . $pid . '.', LOGLEVEL_DEBUG);
135+
exit;
141136
}
142137
}
138+
$app->log('There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.', LOGLEVEL_WARN);
143139
}
144140

145141
// Set Lockfile
146-
@touch($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock');
142+
@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', getmypid());
147143
$app->log('Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', LOGLEVEL_DEBUG);
148144

149145
/** Do we need to start the core-modules */

0 commit comments

Comments
 (0)