[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Cluster-devel] [PATCH] rgmanager: postgresql script now properly recognizes when



Fix for bz#694816

When postgres fails to start the postgres-8.sh now properly detects it.
>From 5e026d222796c4a898b9e157c4a90ac15b0206d9 Mon Sep 17 00:00:00 2001
From: Chris Feist <cfeist redhat com>
Date: Wed, 20 Jul 2011 17:03:23 -0500
Subject: [PATCH] rgmanager: postgresql script now properly recognizes when
 postgres doesn't start.

---
 rgmanager/src/resources/postgres-8.metadata |    4 ++-
 rgmanager/src/resources/postgres-8.sh       |   10 ++++++++-
 rgmanager/src/resources/utils/ra-skelet.sh  |   28 +++++++++++++++++++++++---
 3 files changed, 36 insertions(+), 6 deletions(-)

diff --git a/rgmanager/src/resources/postgres-8.metadata b/rgmanager/src/resources/postgres-8.metadata
index ad3f84e..1af8e84 100644
--- a/rgmanager/src/resources/postgres-8.metadata
+++ b/rgmanager/src/resources/postgres-8.metadata
@@ -53,10 +53,12 @@
 
 	<parameter name="shutdown_wait">
 		<longdesc lang="en">
-			Wait X seconds for correct end of service shutdown
+			Wait X seconds for correct end of service shutdown. 
+			This option is ignored in current release.
 		</longdesc>
 		<shortdesc lang="en">
 			Wait X seconds for correct end of service shutdown
+			This option is ignored in current release.
 		</shortdesc>
 		<content type="integer" />
 	</parameter>
diff --git a/rgmanager/src/resources/postgres-8.sh b/rgmanager/src/resources/postgres-8.sh
index 7a0cc64..5f96b0f 100644
--- a/rgmanager/src/resources/postgres-8.sh
+++ b/rgmanager/src/resources/postgres-8.sh
@@ -28,10 +28,12 @@ export PATH=/bin:/sbin:/usr/bin:/usr/sbin
 . $(dirname $0)/utils/ra-skelet.sh
 
 declare PSQL_POSTMASTER="/usr/bin/postmaster"
+declare PSQL_CTL="/usr/bin/pg_ctl"
 declare PSQL_pid_file="`generate_name_for_pid_file`"
 declare PSQL_conf_dir="`generate_name_for_conf_dir`"
 declare PSQL_gen_config_file="$PSQL_conf_dir/postgresql.conf"
 declare PSQL_kill_timeout="5"
+declare PSQL_wait_after_start="2"
 
 verify_all()
 {
@@ -152,6 +154,11 @@ start()
 	su - "$OCF_RESKEY_postmaster_user" -c "$PSQL_POSTMASTER -c config_file=\"$PSQL_gen_config_file\" \
 		$OCF_RESKEY_postmaster_options" &> /dev/null &
 
+	# We need to sleep for a second to allow pg_ctl to detect that we've started.
+	sleep $PSQL_wait_after_start
+	# We need to fetch "-D /path/to/pgsql/data" from $OCF_RESKEY_postmaster_options
+	su - "$OCF_RESKEY_postmaster_user" -c "$PSQL_CTL status $OCF_RESKEY_postmaster_options" &> /dev/null
+
 	if [ $? -ne 0 ]; then
 		clog_service_start $CLOG_FAILED
 		return $OCF_ERR_GENERIC
@@ -165,7 +172,8 @@ stop()
 {
 	clog_service_stop $CLOG_INIT
 
-	stop_generic_sigkill "$PSQL_pid_file" "$OCF_RESKEY_shutdown_wait" "$PSQL_kill_timeout"
+	## Send -KILL signal immediately
+	stop_generic_sigkill "$PSQL_pid_file" 0 "$PSQL_kill_timeout"
 	if [ $? -ne 0 ]; then
 		clog_service_stop $CLOG_FAILED
 		return $OCF_ERR_GENERIC
diff --git a/rgmanager/src/resources/utils/ra-skelet.sh b/rgmanager/src/resources/utils/ra-skelet.sh
index c832080..a80aac8 100644
--- a/rgmanager/src/resources/utils/ra-skelet.sh
+++ b/rgmanager/src/resources/utils/ra-skelet.sh
@@ -104,19 +104,39 @@ stop_generic_sigkill() {
 	declare kill_timeout="$3"
 	declare pid
 	
-	stop_generic "$pid_file" "$stop_timeout"
-	if [ $? -eq 0 ]; then
-		return 0;
+	## If stop_timeout is equal to zero then we do not want
+	## to give -TERM signal at all.
+	if [ $stop_timeout -ne 0 ]; then
+		stop_generic "$pid_file" "$stop_timeout"
+		if [ $? -eq 0 ]; then
+			return 0;
+		fi
 	fi
 	
+	if [ ! -e "$pid_file" ]; then
+		clog_check_file_exist $CLOG_FAILED_NOT_FOUND "$pid_file"
+		# In stop-after-stop situation there is no PID file but
+		# it will be nice to check for it in stop-after-start
+		# look at bug #449394
+		return 0
+	fi
 	read pid < "$pid_file"
+
+	if [ -z "$pid" ]; then
+		return 0;
+	fi
+
+	if [ ! -d "/proc/$pid" ]; then
+		return 0;
+	fi
+
 	kill -QUIT "$pid"
 	if [ $? -ne 0 ]; then
 		return $OCF_GENERIC_ERROR
 	fi
 	
 	sleep "$kill_timeout"
-	ps --pid "$psql_pid" &> /dev/null
+	ps --pid "$pid" &> /dev/null
 	if [ $? -eq 0 ]; then
 		clog_service_stop $CLOG_FAILED_KILL
 		return $OCF_ERR_GENERIC
-- 
1.7.6


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]