diff --git a/server/cron.php b/server/cron.php
index c197da9516a8d73cc75c44f818be4449a34f2757..e8253a0acdd53c7f03a37df7a6e09240ad56da07 100644
--- a/server/cron.php
+++ b/server/cron.php
@@ -30,6 +30,26 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"]));
 require SCRIPT_PATH."/lib/config.inc.php";
+
+// Check whether another instance of this script is already running
+if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock')) {
+	clearstatcache();
+	$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock'));
+	if(preg_match('/^[0-9]+$/', $pid)) {
+		if(file_exists('/proc/' . $pid)) {
+			print @date('d.m.Y-H:i').' - WARNING - There is already an instance of server.php running with pid ' . $pid . '.' . "\n";
+			exit;
+		}
+	}
+	print @date('d.m.Y-H:i').' - WARNING - There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.' . "\n";
+}
+
+// Set Lockfile
+@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock', getmypid());
+
+if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_cron_lock' . "\n";
+
+
 require SCRIPT_PATH."/lib/app.inc.php";
 
 set_time_limit(0);
diff --git a/server/lib/classes/db_mysql.inc.php b/server/lib/classes/db_mysql.inc.php
index 7c468201206de3135332e63fb8d6702e144e89dd..64ba44ebae2b4a7a1b2d48c417864a57edea8ea1 100644
--- a/server/lib/classes/db_mysql.inc.php
+++ b/server/lib/classes/db_mysql.inc.php
@@ -87,12 +87,12 @@ class db extends mysqli
 
 		if(!is_object($this->_iConnId) || mysqli_connect_error()) {
 			$this->_iConnId = null;
-			$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!');
+			$this->_sqlerror('Zugriff auf Datenbankserver fehlgeschlagen! / Database server not accessible!', '', true);
 			return false;
 		}
 		if(!((bool)mysqli_query( $this->_iConnId, 'USE `' . $this->dbName . '`'))) {
 			$this->close();
-			$this->_sqlerror('Datenbank nicht gefunden / Database not found');
+			$this->_sqlerror('Datenbank nicht gefunden / Database not found', '', true);
 			return false;
 		}
 
@@ -210,7 +210,7 @@ class db extends mysqli
 					}
 
 					if($try > 9) {
-						$this->_sqlerror('DB::query -> reconnect');
+						$this->_sqlerror('DB::query -> reconnect', '', true);
 						return false;
 					} else {
 						sleep(($try > 7 ? 5 : 1));
@@ -464,7 +464,7 @@ class db extends mysqli
 	 *
 	 * @access private
 	 */
-	private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '') {
+	private function _sqlerror($sErrormsg = 'Unbekannter Fehler', $sAddMsg = '', $bNoLog = false) {
 		global $app, $conf;
 
 		$mysql_error = (is_object($this->_iConnId) ? mysqli_error($this->_iConnId) : mysqli_connect_error());
@@ -475,9 +475,11 @@ class db extends mysqli
 
 		if($this->show_error_messages && $conf['demo_mode'] === false) {
 			echo $sErrormsg . $sAddMsg;
-		} else if(is_object($app) && method_exists($app, 'log')) {
-				$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN);
-			}
+		} elseif(is_object($app) && method_exists($app, 'log') && $bNoLog == false) {
+			$app->log($sErrormsg . $sAddMsg . ' -> ' . $mysql_errno . ' (' . $mysql_error . ')', LOGLEVEL_WARN);
+		} elseif(php_sapi_name() == 'cli') {
+			echo $sErrormsg . $sAddMsg;
+		}
 	}
 
 	public function affectedRows() {
diff --git a/server/server.php b/server/server.php
index 4479b147c5504ef304ce1beb3fc5d2a00c19c2c1..689cb174901017229d480e1f3dc920375303507a 100644
--- a/server/server.php
+++ b/server/server.php
@@ -29,6 +29,25 @@
 
 define('SCRIPT_PATH', dirname($_SERVER["SCRIPT_FILENAME"]));
 require SCRIPT_PATH."/lib/config.inc.php";
+
+// Check whether another instance of this script is already running
+if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock')) {
+	clearstatcache();
+	$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock'));
+	if(preg_match('/^[0-9]+$/', $pid)) {
+		if(file_exists('/proc/' . $pid)) {
+			print @date('d.m.Y-H:i').' - WARNING - There is already an instance of server.php running with pid ' . $pid . '.' . "\n";
+			exit;
+		}
+	}
+	print @date('d.m.Y-H:i').' - WARNING - There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.' . "\n";
+}
+
+// Set Lockfile
+@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', getmypid());
+
+if($conf['log_priority'] <= LOGLEVEL_DEBUG) print 'Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock' . "\n";
+
 require SCRIPT_PATH."/lib/app.inc.php";
 
 $app->setCaller('server');
@@ -125,24 +144,6 @@ if ($app->dbmaster->connect_error == NULL) {
 	unset($tmp);
 }
 
-
-// Check whether another instance of this script is already running
-if (is_file($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock')) {
-	clearstatcache();
-	$pid = trim(file_get_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock'));
-	if(preg_match('/^[0-9]+$/', $pid)) {
-		if(file_exists('/proc/' . $pid)) {
-			$app->log('There is already an instance of server.php running with pid ' . $pid . '.', LOGLEVEL_DEBUG);
-			exit;
-		}
-	}
-	$app->log('There is already a lockfile set, but no process running with this pid (' . $pid . '). Continuing.', LOGLEVEL_WARN);
-}
-
-// Set Lockfile
-@file_put_contents($conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', getmypid());
-$app->log('Set Lock: ' . $conf['temppath'] . $conf['fs_div'] . '.ispconfig_lock', LOGLEVEL_DEBUG);
-
 /** Do we need to start the core-modules */