Skip to content

Commit 132081c

Browse files
author
Marius Cramer
committed
- added check for mysql error to avoid flood of error messages/mails
1 parent 6d6643d commit 132081c

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

server/cron_daily.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
require SCRIPT_PATH."/lib/config.inc.php";
3333
require SCRIPT_PATH."/lib/app.inc.php";
3434

35+
$app->setCaller('cron_daily');
36+
3537
set_time_limit(0);
3638
ini_set('error_reporting', E_ALL & ~E_NOTICE);
3739

server/lib/app.inc.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class app {
3535

3636
var $loaded_modules = array();
3737
var $loaded_plugins = array();
38+
var $_calling_script = '';
3839

3940
function __construct() {
4041

@@ -60,6 +61,23 @@ function __construct() {
6061

6162
}
6263

64+
function setCaller($caller) {
65+
$this->_calling_script = $caller;
66+
}
67+
68+
function getCaller() {
69+
return $this->_calling_script;
70+
}
71+
72+
function forceErrorExit($errmsg = 'undefined') {
73+
global $conf;
74+
75+
if($this->_calling_script == 'server') {
76+
@unlink($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock');
77+
}
78+
die('Exiting because of error: ' . $errmsg);
79+
}
80+
6381
function uses($classes) {
6482

6583
global $conf;

server/lib/classes/db_mysql.inc.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ private function setCharacterEncoding() {
130130
}
131131

132132
public function query($queryString) {
133+
global $app;
134+
133135
if($this->isConnected == false) return false;
134136
$try = 0;
135137
do {
@@ -138,6 +140,17 @@ public function query($queryString) {
138140
if(!$ok) {
139141
if(!$this->real_connect($this->dbHost, $this->dbUser, $this->dbPass, $this->dbName)) {
140142
$this->updateError('DB::query -> reconnect');
143+
if($this->errorNumber == '111') {
144+
// server is not available
145+
if($try > 9) {
146+
if(isset($app) && isset($app->forceErrorExit)) {
147+
$app->forceErrorExit('Database connection failure!');
148+
}
149+
// if we reach this, the app object is missing or has no exit method, so we continue as normal
150+
}
151+
sleep(30); // additional seconds, please!
152+
}
153+
141154
if($try > 9) {
142155
return false;
143156
} else {

server/server.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
require SCRIPT_PATH."/lib/config.inc.php";
3232
require SCRIPT_PATH."/lib/app.inc.php";
3333

34+
$app->setCaller('server');
35+
3436
set_time_limit(0);
3537
ini_set('error_reporting', E_ALL & ~E_NOTICE);
3638

0 commit comments

Comments
 (0)