Skip to content

Commit 611407e

Browse files
author
Marius Burkard
committed
- moved lock file to front of file
- disabled database logging of sql reconnect errors, fixed #3974
1 parent cae2518 commit 611407e

File tree

3 files changed

+48
-25
lines changed

3 files changed

+48
-25
lines changed

server/cron.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,26 @@
3030

3131
define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"]));
3232
require SCRIPT_PATH."/lib/config.inc.php";
33+
34+
// Check whether another instance of this script is already running
35+
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')) {
36+
clearstatcache();
37+
$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock'));
38+
if(preg_match('/^[0-9]+$/', $pid)) {
39+
if(file_exists('/proc/' . $pid)) {
40+
print @date('d.m.Y-H:i').' - WARNING - There is already an instance of server.php running with pid ' . $pid . '.' . "\n";
41+
exit;
42+
}
43+
}
44+
print @date('d.m.Y-H:i').' - WARNING - There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.' . "\n";
45+
}
46+
47+
// Set Lockfile
48+
@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', getmypid());
49+
50+
if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock' . "\n";
51+
52+
3353
require SCRIPT_PATH."/lib/app.inc.php";
3454

3555
set_time_limit(0);

server/lib/classes/db_mysql.inc.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ public function __construct($host = NULL , $user = NULL, $pass = NULL, $database
8787

8888
if(!is_object($this->_iConnId) || mysqli_connect_error()) {
8989
$this->_iConnId = null;
90-
$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!');
90+
$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!', '', true);
9191
return false;
9292
}
9393
if(!((bool)mysqli_query( $this->_iConnId, 'USE `' . $this->dbName . '`'))) {
9494
$this->close();
95-
$this->_sqlerror('Datenbank nicht gefunden / Database not found');
95+
$this->_sqlerror('Datenbank nicht gefunden / Database not found', '', true);
9696
return false;
9797
}
9898

@@ -210,7 +210,7 @@ private function _query($sQuery = '') {
210210
}
211211

212212
if($try > 9) {
213-
$this->_sqlerror('DB::query -> reconnect');
213+
$this->_sqlerror('DB::query -> reconnect', '', true);
214214
return false;
215215
} else {
216216
sleep(($try > 7 ? 5 : 1));
@@ -464,7 +464,7 @@ public function escape($sString) {
464464
*
465465
* @access private
466466
*/
467-
private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '') {
467+
private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '', $bNoLog = false) {
468468
global $app, $conf;
469469

470470
$mysql_error = (is_object($this->_iConnId) ? mysqli_error($this->_iConnId) : mysqli_connect_error());
@@ -475,9 +475,11 @@ private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '') {
475475

476476
if($this->show_error_messages && $conf['demo_mode'] === false) {
477477
echo $sErrormsg . $sAddMsg;
478-
} else if(is_object($app) && method_exists($app, 'log')) {
479-
$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN);
480-
}
478+
} elseif(is_object($app) && method_exists($app, 'log') && $bNoLog == false) {
479+
$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN);
480+
} elseif(php_sapi_name() == 'cli') {
481+
echo $sErrormsg . $sAddMsg;
482+
}
481483
}
482484

483485
public function affectedRows() {

server/server.php

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,25 @@
2929

3030
define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"]));
3131
require SCRIPT_PATH."/lib/config.inc.php";
32+
33+
// Check whether another instance of this script is already running
34+
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock')) {
35+
clearstatcache();
36+
$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock'));
37+
if(preg_match('/^[0-9]+$/', $pid)) {
38+
if(file_exists('/proc/' . $pid)) {
39+
print @date('d.m.Y-H:i').' - WARNING - There is already an instance of server.php running with pid ' . $pid . '.' . "\n";
40+
exit;
41+
}
42+
}
43+
print @date('d.m.Y-H:i').' - WARNING - There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.' . "\n";
44+
}
45+
46+
// Set Lockfile
47+
@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', getmypid());
48+
49+
if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock' . "\n";
50+
3251
require SCRIPT_PATH."/lib/app.inc.php";
3352

3453
$app->setCaller('server');
@@ -125,24 +144,6 @@
125144
unset($tmp);
126145
}
127146

128-
129-
// Check whether another instance of this script is already running
130-
if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock')) {
131-
clearstatcache();
132-
$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock'));
133-
if(preg_match('/^[0-9]+$/', $pid)) {
134-
if(file_exists('/proc/' . $pid)) {
135-
$app->log('There is already an instance of server.php running with pid ' . $pid . '.', LOGLEVEL_DEBUG);
136-
exit;
137-
}
138-
}
139-
$app->log('There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.', LOGLEVEL_WARN);
140-
}
141-
142-
// Set Lockfile
143-
@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', getmypid());
144-
$app->log('Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', LOGLEVEL_DEBUG);
145-
146147
/** Do we need to start the core-modules */
147148

148149

0 commit comments

Comments
 (0)