From b9a3ef486ebcde18a5ade37865ff8f397185d24f Mon Sep 17 00:00:00 2001
From: Till Brehm <tbrehm@ispconfig.org>
Date: Sun, 24 Jul 2016 05:30:59 -0400
Subject: [PATCH] Fixed #3979 Mailbox users unable to save autoresponders

---
 server/mods-available/rescue_core_module.inc.php |   70 ++++++++++++++++++++--------------
 1 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/server/mods-available/rescue_core_module.inc.php b/server/mods-available/rescue_core_module.inc.php
index 94d7ba6..5e8f3db 100644
--- a/server/mods-available/rescue_core_module.inc.php
+++ b/server/mods-available/rescue_core_module.inc.php
@@ -97,7 +97,7 @@
 		/*
 		 * rescue MongoDB if needed
 		 */
-		$this->_rescueMongoDB();
+//		$this->_rescueMongoDB();
 
 		/*
 		 * rescue mysql if needed (maybe httpd depends on mysql, so try this first!)
@@ -275,6 +275,17 @@
 
 		/* Set the new try counter */
 		$this->_rescueData['webserver']['try_counter'] = $tryCount;
+		
+		if ($tryCount > 2 && $conf['serverconfig']['web']['server_type'] != 'nginx') {
+			if($app->system->is_user('apache')) {
+				$app->log("Clearing semaphores table for user apache.",LOGLEVEL_WARN);
+				exec("ipcs -s | grep apache | awk '{ print $2 }' | xargs ipcrm sem");
+			}
+			if($app->system->is_user('www-data')) {
+				$app->log("Clearing semaphores table for user apache.",LOGLEVEL_WARN);
+				exec("ipcs -s | grep www-data | awk '{ print $2 }' | xargs ipcrm sem");
+			}
+		}
 
 		/* if 5 times will not work, we have to give up... */
 		if ($tryCount > 5){
@@ -300,42 +311,43 @@
 		$this->_rescueDaemon($daemon);
 	}
 
+
 	/**
 	 * restarts MongoDB, if needed
 	 */
-	private function _rescueMongoDB(){
-		global $app, $conf;
+//	private function _rescueMongoDB(){
+//		global $app, $conf;
 
 		/*
 		 * do nothing, if it is not allowed to rescue mysql
 		 */
-		if ((isset($conf['serverconfig']['rescue']['do_not_try_rescue_mongodb']) && ($conf['serverconfig']['rescue']['do_not_try_rescue_mongodb']) == 'y')){
-			return;
-		}
+//		if ((isset($conf['serverconfig']['rescue']['do_not_try_rescue_mongodb']) && ($conf['serverconfig']['rescue']['do_not_try_rescue_mongodb']) == 'y')){
+//			return;
+//		}
 
 		/*
 		 * if the service is up and running, or the service is not installed there is nothing to do...
 		 */
-		if ($this->_monitoringData[0][0]['data']['mongodbserver'] != 0){
-			/* Clear the try counter, because we do not have to try to rescue the service */
-			$this->_rescueData['mongodbserver']['try_counter'] = 0;
-			return;
-		}
+//		if ($this->_monitoringData[0][0]['data']['mongodbserver'] != 0){
+//			/* Clear the try counter, because we do not have to try to rescue the service */
+//			$this->_rescueData['mongodbserver']['try_counter'] = 0;
+//			return;
+//		}
 
 		/*
 		 * OK, the service is installed and down.
 		 * Maybe this is because of a restart of the service by the admin.
 		 * This means, we check the data 1 minute ago
 		 */
-		if ((!isset($this->_monitoringData[1][0]['data']['mongodbserver'])) ||
-			((isset($this->_monitoringData[1][0]['data']['mongodbserver'])) && ($this->_monitoringData[1][0]['data']['mongodbserver'] != 0))){
+//		if ((!isset($this->_monitoringData[1][0]['data']['mongodbserver'])) ||
+//			((isset($this->_monitoringData[1][0]['data']['mongodbserver'])) && ($this->_monitoringData[1][0]['data']['mongodbserver'] != 0))){
 			/*
 			 * We do NOT have this data or we have this data, but the webserver was not down 1 minute ago.
 			 * This means, it could be, that the admin is restarting the server.
 			 * We wait one more minute...
 			 */
-			return;
-		}
+//			return;
+//		}
 
 		/*#####
 		 * The service is down and it was down 1 minute ago.
@@ -343,28 +355,28 @@
 		 *#####*/
 
 		/* Get the try counter */
-		$tryCount = (!isset($this->_rescueData['mongodbserver']['try_counter']))? 1 : $this->_rescueData['mongodbserver']['try_counter'] + 1;
+//		$tryCount = (!isset($this->_rescueData['mongodbserver']['try_counter']))? 1 : $this->_rescueData['mongodbserver']['try_counter'] + 1;
 
 		/* Set the new try counter */
-		$this->_rescueData['mongodbserver']['try_counter'] = $tryCount;
+//		$this->_rescueData['mongodbserver']['try_counter'] = $tryCount;
 
 		/* if 5 times will not work, we have to give up... */
-		if ($tryCount > 5){
-			$app->log('MongoDB is down! Rescue will not help!', LOGLEVEL_ERROR);
-			return;
-		}
+//		if ($tryCount > 5){
+//			$app->log('MongoDB is down! Rescue will not help!', LOGLEVEL_ERROR);
+//			return;
+//		}
 
 
-		$app->log('MongoDB is down! Try rescue MongoDB (try:' . $tryCount . ')...', LOGLEVEL_WARN);
+//		$app->log('MongoDB is down! Try rescue MongoDB (try:' . $tryCount . ')...', LOGLEVEL_WARN);
 
-		if(is_file($conf['init_scripts'] . '/' . 'mongodb')) {
-			$daemon = 'mongodb';
-		} else {
-			$daemon = 'mongodb';
-		}
+//		if(is_file($conf['init_scripts'] . '/' . 'mongodb')) {
+//			$daemon = 'mongodb';
+//		} else {
+//			$daemon = 'mongodb';
+//		}
 
-		$this->_rescueDaemon($daemon);
-	}
+//		$this->_rescueDaemon($daemon);
+//	}
 
 	/**
 	 * restarts mysql, if needed

--
Gitblit v1.9.1