From 7d52e00a51450bc4a080d4e21b7dda02c0a65191 Mon Sep 17 00:00:00 2001
From: Marius Cramer <m.cramer@pixcept.de>
Date: Thu, 14 Nov 2013 05:42:06 -0500
Subject: [PATCH] Fixed list sorting

---
 server/mods-available/rescue_core_module.inc.php |   45 +++++++++++++++++++++++++--------------------
 1 files changed, 25 insertions(+), 20 deletions(-)

diff --git a/server/mods-available/rescue_core_module.inc.php b/server/mods-available/rescue_core_module.inc.php
index 6a86344..15abd54 100644
--- a/server/mods-available/rescue_core_module.inc.php
+++ b/server/mods-available/rescue_core_module.inc.php
@@ -89,14 +89,14 @@
 		$this->_rescueData = $this->_getRescueData();
 		
 		/*
-		 * rescue apache if needed
-		 */
-		$this->_rescueApache();
-		
-		/*
-		 * rescue mysql if needed
+		 * rescue mysql if needed (maybe httpd depends on mysql, so try this first!)
 		 */
 		$this->_rescueMySql();
+		
+		/*
+		 * rescue httpd if needed
+		 */
+		$this->_rescueHttpd();
 		
 		/*
 		 * The last step is to save the rescue-data
@@ -218,15 +218,15 @@
 	}
 
 	/**
-	 * restarts apache, if needed
+	 * restarts httpd, if needed
 	 */
-	private function _rescueApache(){
+	private function _rescueHttpd(){
 		global $app, $conf;
 		
 		/*
-		 * do nothing, if it is not allowed to rescue apache
+		 * do nothing, if it is not allowed to rescue httpd
 		 */
-		if ((isset($conf['serverconfig']['rescue']['do_not_try_rescue_apache']) && ($conf['serverconfig']['rescue']['do_not_try_rescue_apache']) == 'y')){
+		if ((isset($conf['serverconfig']['rescue']['do_not_try_rescue_httpd']) && ($conf['serverconfig']['rescue']['do_not_try_rescue_httpd']) == 'y')){
 			return;
 		}
 		
@@ -267,18 +267,23 @@
 		
 		/* if 5 times will not work, we have to give up... */
 		if ($tryCount > 5){
-			$app->log('Apache is down! Rescue will not help!', LOGLEVEL_ERROR);
+			$app->log('httpd is down! Rescue will not help!', LOGLEVEL_ERROR);
 			return;
 		}
 		
 		
-		$app->log('Apache is down! Try rescue apache (try:' . $tryCount . ')...', LOGLEVEL_WARN);
-//		echo 'Apache is down! Try rescue apache (try:' . $tryCount . ')...';
-
-		if(is_file($conf['init_scripts'] . '/' . 'httpd')) {
-			$daemon = 'httpd';
+		$app->log('httpd is down! Try rescue httpd (try:' . $tryCount . ')...', LOGLEVEL_WARN);
+		
+		if($conf['serverconfig']['web']['server_type'] == 'nginx'){
+			$daemon = 'nginx';
 		} else {
-			$daemon = 'apache2';
+			if(is_file($conf['init_scripts'] . '/' . 'httpd')) {
+				$daemon = 'httpd';
+			} elseif(is_file($conf['init_scripts'] . '/' . 'httpd2')){
+				$daemon = 'httpd2';
+			} else {
+				$daemon = 'apache2';
+			}
 		}
 		
 		$this->_rescueDaemon($daemon);
@@ -340,7 +345,6 @@
 		
 		
 		$app->log('MySQL is down! Try rescue mysql (try:' . $tryCount . ')...', LOGLEVEL_WARN);
-//		echo 'MySQL is down! Try rescue mysql (try:' . $tryCount . ')...';
 
 		if(is_file($conf['init_scripts'] . '/' . 'mysqld')) {
 			$daemon = 'mysqld';
@@ -359,6 +363,7 @@
 	private function _rescueDaemon($daemon){
 		global $conf;
 		
+		$app->uses('system');
 		// if you need to find all restarts search for "['init_scripts']"
 		/*
 		 * First we stop the running service "normally"
@@ -370,7 +375,7 @@
 		 * So we have to try to stop but if this will not work, we have to kill the stopping
 		 * of the service
 		 */
-		exec($conf['init_scripts'] . '/' . $daemon . ' stop && (sleep 3; kill $!; sleep 2; kill -9 $!) &> /dev/null');
+		exec($app->system->getinitcommand($daemon, 'stop').' && (sleep 3; kill $!; sleep 2; kill -9 $!) &> /dev/null');
 		
 		/*
 		 * OK, we tryed to stop it normally, maybe this worked maybe not. So we have to look
@@ -381,7 +386,7 @@
 		/*
 		 * There are no more zombies left. Lets start the service..
 		 */
-		exec($conf['init_scripts'] . '/' . $daemon . ' start');
+		exec($app->system->getinitcommand($daemon, 'start'));
 	}
 }
 ?>

--
Gitblit v1.9.1