Blame SOURCES/bz1436189-sybase.patch

bb196a
diff -uNr a/doc/man/Makefile.am b/doc/man/Makefile.am
bb196a
--- a/doc/man/Makefile.am	2017-08-30 15:55:08.646159027 +0200
bb196a
+++ b/doc/man/Makefile.am	2017-08-30 15:58:31.899477013 +0200
bb196a
@@ -140,6 +140,7 @@
bb196a
                           ocf_heartbeat_scsi2reservation.7 \
bb196a
                           ocf_heartbeat_sfex.7 \
bb196a
                           ocf_heartbeat_slapd.7 \
bb196a
+                          ocf_heartbeat_sybaseASE.7 \
bb196a
                           ocf_heartbeat_symlink.7 \
bb196a
                           ocf_heartbeat_syslog-ng.7 \
bb196a
                           ocf_heartbeat_tomcat.7 \
bb196a
diff -uNr a/heartbeat/Makefile.am b/heartbeat/Makefile.am
bb196a
--- a/heartbeat/Makefile.am	2017-08-30 15:55:08.646159027 +0200
bb196a
+++ b/heartbeat/Makefile.am	2017-08-30 15:58:31.899477013 +0200
bb196a
@@ -131,6 +131,7 @@
bb196a
 			SysInfo			\
bb196a
 			scsi2reservation	\
bb196a
 			sfex			\
bb196a
+			sybaseASE		\
bb196a
 			symlink			\
bb196a
 			syslog-ng		\
bb196a
 			tomcat			\
bb196a
diff -uNr a/heartbeat/sybaseASE b/heartbeat/sybaseASE
bb196a
--- a/heartbeat/sybaseASE	1970-01-01 01:00:00.000000000 +0100
bb196a
+++ b/heartbeat/sybaseASE	2017-08-30 14:51:24.000000000 +0200
bb196a
@@ -0,0 +1,894 @@
bb196a
+#!/bin/bash
bb196a
+
bb196a
+# 
bb196a
+# Sybase Availability Agent for Red Hat Cluster v15.0.2 
bb196a
+# Copyright (C) - 2007
bb196a
+# Sybase, Inc. All rights reserved.
bb196a
+#
bb196a
+# Sybase Availability Agent for Red Hat Cluster v15.0.2 is licensed
bb196a
+# under the GNU General Public License Version 2.
bb196a
+#
bb196a
+# Author(s):
bb196a
+#    Jian-ping Hui <jphui@sybase.com>
bb196a
+#
bb196a
+# Description: Service script for starting/stopping/monitoring \
bb196a
+#              Sybase Adaptive Server on: \
bb196a
+#                            Red Hat Enterprise Linux 5 ES \
bb196a
+#                            Red Hat Enterprise Linux 5 AS
bb196a
+#
bb196a
+# NOTES:
bb196a
+#
bb196a
+# (1) Before running this script, we assume that user has installed
bb196a
+#     Sybase ASE 15.0.2 or higher version on the machine. Please
bb196a
+#     customize your configuration in /etc/cluster/cluster.conf according
bb196a
+#     to your actual environment. We assume the following files exist before
bb196a
+#     you start the service:
bb196a
+#         /$sybase_home/SYBASE.sh
bb196a
+#         /$sybase_home/$sybase_ase/install/RUN_$server_name
bb196a
+#
bb196a
+# (2) You can customize the interval value in the meta-data section if needed:
bb196a
+#                <action name="start" timeout="300" />
bb196a
+#                <action name="stop" timeout="300" />
bb196a
+#                
bb196a
+#                
bb196a
+#                <action name="status"  interval="30" timeout="100" />
bb196a
+#                <action name="monitor" interval="30" timeout="100" />
bb196a
+#                
bb196a
+#                
bb196a
+#                <action name="status" depth="10" timeout="100" interval="120" />
bb196a
+#                <action name="monitor" depth="10" timeout="100" interval="120" />
bb196a
+#                
bb196a
+#                <action name="meta-data" timeout="5" />
bb196a
+#                <action name="validate-all" timeout="5" />
bb196a
+#     The timeout value is not supported by Redhat in RHCS5.0. 
bb196a
+# 
bb196a
+# (3) This script should be put under /usr/share/cluster. Its owner should be "root" with 
bb196a
+#     execution permission.
bb196a
+#
bb196a
+
bb196a
+#######################################################################
bb196a
+# Initialization:
bb196a
+
bb196a
+. /etc/init.d/functions
bb196a
+: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
bb196a
+. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
bb196a
+
bb196a
+#######################################################################
bb196a
+
bb196a
+# Default timeouts when we aren't using the rgmanager wrapper
bb196a
+if ! ocf_is_true "$OCF_RESKEY_is_rgmanager_wrapper"; then
bb196a
+	if [ -z "$OCF_RESKEY_CRM_meta_timeout" ]; then
bb196a
+		case $1 in
bb196a
+			start|stop) OCF_RESKEY_CRM_meta_timeout=300000 ;;
bb196a
+			*) OCF_RESKEY_CRM_meta_timeout=100000 ;;
bb196a
+		esac
bb196a
+	fi
bb196a
+	default_timeout=$(((${OCF_RESKEY_CRM_meta_timeout}/1000) - 5))
bb196a
+	default_force_stop_timeout=$(((${OCF_RESKEY_CRM_meta_timeout}/1000) - 5))
bb196a
+	: ${OCF_RESKEY_shutdown_timeout=${default_force_stop_timeout}}
bb196a
+	: ${OCF_RESKEY_deep_probe_timeout=${default_timeout}}
bb196a
+	: ${OCF_RESKEY_start_timeout=${default_timeout}}
bb196a
+fi
bb196a
+
bb196a
+sybase_user_default="sybase"
bb196a
+sybase_home_default="detect"
bb196a
+ase_default="detect"
bb196a
+ocs_default="detect"
bb196a
+
bb196a
+: ${OCF_RESKEY_sybase_user=${sybase_user_default}}
bb196a
+: ${OCF_RESKEY_sybase_ase=${ase_default}}
bb196a
+: ${OCF_RESKEY_sybase_ocs=${ocs_default}}
bb196a
+: ${OCF_RESKEY_sybase_home=${sybase_home_default}}
bb196a
+
bb196a
+if [ "$OCF_RESKEY_sybase_home" = "detect" ]; then
bb196a
+	if [ -d "/opt/sap" ]; then
bb196a
+		OCF_RESKEY_sybase_home="/opt/sap"
bb196a
+	elif [ -d "/opt/sybase" ]; then
bb196a
+		OCF_RESKEY_sybase_home="/opt/sybase"
bb196a
+	else
bb196a
+		ocf_log err "sybaseASE: Unable to detect 'sybase_home'."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+fi
bb196a
+
bb196a
+sybase_env="$OCF_RESKEY_sybase_home/SYBASE.env"
bb196a
+
bb196a
+if [ "$OCF_RESKEY_sybase_ase" = "detect" ]; then
bb196a
+	if [ -f "$sybase_env" ]; then
bb196a
+		OCF_RESKEY_sybase_ase=$(grep "SYBASE_ASE" "$sybase_env" | cut -d= -f2)
bb196a
+	else
bb196a
+		ocf_log err "sybaseASE: Unable to detect 'sybase_ase'."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+fi
bb196a
+
bb196a
+if [ "$OCF_RESKEY_sybase_ocs" = "detect" ]; then
bb196a
+	if [ -f "$sybase_env" ]; then
bb196a
+		OCF_RESKEY_sybase_ocs=$(grep "SYBASE_OCS" "$sybase_env" | cut -d= -f2)
bb196a
+	else
bb196a
+		ocf_log err "sybaseASE: Unable to detect 'sybase_ocs'."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+fi
bb196a
+
bb196a
+
bb196a
+interfaces_file_default="${OCF_RESKEY_sybase_home}/interfaces"
bb196a
+: ${OCF_RESKEY_interfaces_file=${interfaces_file_default}}
bb196a
+
bb196a
+export LD_POINTER_GUARD=0
bb196a
+
bb196a
+#######################################################################################
bb196a
+# Declare some variables we will use in the script. Please don't change their values. #
bb196a
+#######################################################################################
bb196a
+declare login_string=""
bb196a
+declare RUNSERVER_SCRIPT=$OCF_RESKEY_sybase_home/$OCF_RESKEY_sybase_ase/install/RUN_$OCF_RESKEY_server_name
bb196a
+declare CONSOLE_LOG=$OCF_RESKEY_sybase_home/$OCF_RESKEY_sybase_ase/install/$OCF_RESKEY_server_name.log
bb196a
+
bb196a
+##################################################################################################
bb196a
+# This function will be called by rgmanager to get the meta data of resource agent "sybaseASE". #
bb196a
+# NEVER CHANGE ANYTHING IN THIS FUNCTION.
bb196a
+##################################################################################################
bb196a
+meta_data()
bb196a
+{
bb196a
+	cat <
bb196a
+
bb196a
+
bb196a
+<resource-agent name="sybaseASE" >
bb196a
+	<version>1.0</version>
bb196a
+
bb196a
+	<longdesc lang="en">
bb196a
+		Sybase ASE Failover Instance
bb196a
+	</longdesc>
bb196a
+	<shortdesc lang="en">
bb196a
+		Sybase ASE Failover Instance
bb196a
+	</shortdesc>
bb196a
+
bb196a
+	<parameters>
bb196a
+		<parameter name="sybase_home">
bb196a
+			<longdesc lang="en">
bb196a
+				The home directory of sybase products
bb196a
+			</longdesc>
bb196a
+			<shortdesc lang="en">
bb196a
+				SYBASE home directory
bb196a
+			</shortdesc>
bb196a
+			<content type="string" default="${sybase_home_default}"/>
bb196a
+		</parameter>
bb196a
+
bb196a
+		<parameter name="sybase_ase">
bb196a
+			<longdesc lang="en">
bb196a
+				The directory name under sybase_home where ASE products are installed
bb196a
+			</longdesc>
bb196a
+			<shortdesc lang="en">
bb196a
+				SYBASE_ASE directory name
bb196a
+			</shortdesc>
bb196a
+			<content type="string" default="$ase_default" />
bb196a
+		</parameter>
bb196a
+
bb196a
+		<parameter name="sybase_ocs">
bb196a
+			<longdesc lang="en">
bb196a
+				The directory name under sybase_home where OCS products are installed, i.e. ASE-15_0
bb196a
+			</longdesc>
bb196a
+			<shortdesc lang="en">
bb196a
+				SYBASE_OCS directory name
bb196a
+			</shortdesc>
bb196a
+			<content type="string" default="${ocs_default}" />
bb196a
+		</parameter>
bb196a
+
bb196a
+		<parameter name="server_name" unique="1" required="1">
bb196a
+			<longdesc lang="en">
bb196a
+				The ASE server name which is configured for the HA service
bb196a
+			</longdesc>
bb196a
+			<shortdesc lang="en">
bb196a
+				ASE server name
bb196a
+			</shortdesc>
bb196a
+			<content type="string" />
bb196a
+		</parameter>
bb196a
+
bb196a
+		<parameter name="interfaces_file">
bb196a
+			<longdesc lang="en">
bb196a
+				The full path of interfaces file which is used to start/access the ASE server
bb196a
+			</longdesc>
bb196a
+			<shortdesc lang="en">
bb196a
+				Interfaces file
bb196a
+			</shortdesc>
bb196a
+			<content type="string" default="$interfaces_file_default"/>
bb196a
+		</parameter>
bb196a
+
bb196a
+		<parameter name="sybase_user">
bb196a
+			<longdesc lang="en">
bb196a
+				The user who can run ASE server
bb196a
+			</longdesc>
bb196a
+			<shortdesc lang="en">
bb196a
+				Sybase user
bb196a
+			</shortdesc>
bb196a
+			<content type="string" default="$sybase_user_default" />
bb196a
+		</parameter>
bb196a
+
bb196a
+		<parameter name="db_user" required="1">
bb196a
+			<longdesc lang="en">
bb196a
+				The database user required to login to isql.
bb196a
+			</longdesc>
bb196a
+			<shortdesc lang="en">
bb196a
+				Sybase user
bb196a
+			</shortdesc>
bb196a
+			<content type="string"/>
bb196a
+		</parameter>
bb196a
+
bb196a
+		<parameter name="db_passwd">
bb196a
+			<longdesc lang="en">
bb196a
+				The database user's password required to login to isql.
bb196a
+			</longdesc>
bb196a
+			<shortdesc lang="en">
bb196a
+				Sybase user
bb196a
+			</shortdesc>
bb196a
+			<content type="string"/>
bb196a
+		</parameter>
bb196a
+
bb196a
+	</parameters>
bb196a
+
bb196a
+	<actions>
bb196a
+		<action name="start" timeout="300" />
bb196a
+		<action name="stop" timeout="300" />
bb196a
+		
bb196a
+		
bb196a
+		<action name="status"  interval="30" timeout="100" />
bb196a
+		<action name="monitor" interval="30" timeout="100" />
bb196a
+		
bb196a
+		
bb196a
+		<action name="status" depth="10" timeout="100" interval="120" />
bb196a
+		<action name="monitor" depth="10" timeout="100" interval="120" />
bb196a
+		
bb196a
+		<action name="meta-data" timeout="5" />
bb196a
+		<action name="validate-all" timeout="5" />
bb196a
+	</actions>
bb196a
+
bb196a
+	<special tag="rgmanager">
bb196a
+	</special>
bb196a
+</resource-agent>
bb196a
+EOT
bb196a
+}
bb196a
+
bb196a
+ase_engine0_process()
bb196a
+{
bb196a
+	sed -n -e '/engine 0/s/^.*os pid \([0-9]*\).*online$/\1/p' $CONSOLE_LOG
bb196a
+}
bb196a
+
bb196a
+ase_engine0_thread()
bb196a
+{
bb196a
+	sed -n -e 's/.*Thread.*LWP \([0-9]*\).*online as engine 0.*/\1/p' $CONSOLE_LOG
bb196a
+}
bb196a
+
bb196a
+ase_engine_threadpool_pid()
bb196a
+{
bb196a
+	sed -n -e 's/.*Adaptive Server is running as process id \([0-9]*\).*/\1/p' $CONSOLE_LOG
bb196a
+}
bb196a
+
bb196a
+ase_all_pids()
bb196a
+{
bb196a
+	local PIDS=$(sed -n -e '/engine /s/^.*os pid \([0-9]*\).*online$/\1/p' $CONSOLE_LOG)
bb196a
+	if [ -z "$PIDS" ]; then
bb196a
+		#engines are running in a threadpool
bb196a
+		PIDS=$(ase_engine_threadpool_pid)
bb196a
+	fi
bb196a
+	echo $PIDS
bb196a
+}
bb196a
+
bb196a
+##################################################################################################
bb196a
+# Function Name: verify_all                                                                      #
bb196a
+# Parameter: None                                                                                #
bb196a
+# Return value:                                                                                  #
bb196a
+#             0               SUCCESS                                                            #
bb196a
+#             OCF_ERR_ARGS    Parameters are invalid                                             #
bb196a
+# Description: Do some validation on the user-configurable stuff at the beginning of the script. #
bb196a
+##################################################################################################
bb196a
+verify_all() 
bb196a
+{
bb196a
+	ocf_log debug "sybaseASE: Start 'verify_all'"
bb196a
+
bb196a
+	check_binary "ksh"
bb196a
+
bb196a
+	# Check if the parameter 'sybase_home' is set.	
bb196a
+	if [[ -z "$OCF_RESKEY_sybase_home" ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'sybase_home' is not set."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'sybase_home' is a valid path.
bb196a
+	if [[ ! -d $OCF_RESKEY_sybase_home ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The sybase_home '$OCF_RESKEY_sybase_home' doesn't exist."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the script file SYBASE.sh exists
bb196a
+	if [[ ! -f $OCF_RESKEY_sybase_home/SYBASE.sh ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The file $OCF_RESKEY_sybase_home/SYBASE.sh is required to run this script. Failed to run the script."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'sybase_ase' is set.
bb196a
+	if [[ -z "$OCF_RESKEY_sybase_ase" ]] 
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'sybase_ase' is not set."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the directory /$OCF_RESKEY_sybase_home/$OCF_RESKEY_sybase_ase exists.
bb196a
+	if [[ ! -d $OCF_RESKEY_sybase_home/$OCF_RESKEY_sybase_ase ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The directory '$OCF_RESKEY_sybase_home/$OCF_RESKEY_sybase_ase' doesn't exist."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'sybase_ocs' is set.
bb196a
+	if [[ -z "$OCF_RESKEY_sybase_ocs" ]] 
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'sybase_ocs' is not set."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the directory /$OCF_RESKEY_sybase_home/$OCF_RESKEY_sybase_ocs exists.
bb196a
+	if [[ ! -d $OCF_RESKEY_sybase_home/$OCF_RESKEY_sybase_ocs ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The directory '$OCF_RESKEY_sybase_home/$OCF_RESKEY_sybase_ocs' doesn't exist."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'server_name' is set.	
bb196a
+	if [[ -z "$OCF_RESKEY_server_name" ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'server_name' is not set."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the Run_server file exists.
bb196a
+	if [[ ! -f $RUNSERVER_SCRIPT ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The file $RUNSERVER_SCRIPT doesn't exist. The sybase directory may be incorrect."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the user 'sybase_user' exist
bb196a
+	id -u $OCF_RESKEY_sybase_user
bb196a
+	if [[ $? != 0 ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The user '$OCF_RESKEY_sybase_user' doesn't exist in the system."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'interfaces_file' is set
bb196a
+	if [[ -z "$OCF_RESKEY_interfaces_file" ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'interfaces_file' is not set."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the file 'interfaces_file' exists
bb196a
+	if [[ ! -f $OCF_RESKEY_interfaces_file ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The interfaces file '$OCF_RESKEY_interfaces_file' doesn't exist."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'db_user' is set
bb196a
+	if [[ -z "$OCF_RESKEY_db_user" ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'db_user' is not set."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'shutdown_timeout' is a valid value
bb196a
+	if [[ $OCF_RESKEY_shutdown_timeout -eq 0 ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'shutdown_timeout' is not set. Its value cannot be zero."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'start_timeout' is a valid value
bb196a
+	if [[ $OCF_RESKEY_start_timeout -eq 0 ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'start_timeout' is not set. Its value cannot be zero."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	# Check if the parameter 'deep_probe_timeout' is a valid value
bb196a
+	if [[ $OCF_RESKEY_deep_probe_timeout -eq 0 ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: The parameter 'deep_probe_timeout' is not set. Its value cannot be zero."
bb196a
+		return $OCF_ERR_ARGS
bb196a
+	fi
bb196a
+
bb196a
+	ocf_log debug "sybaseASE: End 'verify_all' successfully."
bb196a
+
bb196a
+	return $OCF_SUCCESS
bb196a
+}
bb196a
+
bb196a
+set_login_string()
bb196a
+{
bb196a
+	tmpstring=""
bb196a
+	login_sting=""
bb196a
+
bb196a
+	login_string="-U$OCF_RESKEY_db_user -P$OCF_RESKEY_db_passwd"
bb196a
+	return 0
bb196a
+}
bb196a
+
bb196a
+##############################################################################################
bb196a
+# Function name: ase_start                                                                   #
bb196a
+# Parameter: None                                                                            #
bb196a
+# Return value:                                                                              #
bb196a
+#             0  SUCCESS                                                                     #
bb196a
+#             1  FAIL                                                                        #
bb196a
+# Description: This function is used to start the ASE server in primary or secondary server. #
bb196a
+##############################################################################################
bb196a
+ase_start()
bb196a
+{
bb196a
+	ocf_log debug "sybaseASE: Start 'ase_start'"
bb196a
+
bb196a
+	# Check if the server is running. If yes, return SUCCESS directly. Otherwise, continue the start work.
bb196a
+	ase_is_running
bb196a
+	if [[ $? = 0 ]]
bb196a
+	then
bb196a
+		# The server is running. 
bb196a
+		ocf_log info "sybaseASE: Server is running. Start is success."
bb196a
+		return $OCF_SUCCESS
bb196a
+	fi
bb196a
+
bb196a
+	# The server is not running. We need to start it.
bb196a
+	# If the log file existed, delete it.
bb196a
+	if [[ -f $CONSOLE_LOG ]]
bb196a
+	then
bb196a
+		rm -f $CONSOLE_LOG
bb196a
+	fi
bb196a
+		
bb196a
+	ocf_log debug "sybaseASE: Starting '$OCF_RESKEY_server_name'..."
bb196a
+
bb196a
+	# Run runserver script to start the server. Since this script will be run by root and ASE server
bb196a
+	# needs to be run by another user, we need to change the user to sybase_user first. Then, run
bb196a
+	# the script to start the server.
bb196a
+	su $OCF_RESKEY_sybase_user -c ksh << EOF
bb196a
+		# set required SYBASE environment by running SYBASE.sh.
bb196a
+		. $OCF_RESKEY_sybase_home/SYBASE.sh
bb196a
+		# Run the RUNSERVER_SCRIPT to start the server.
bb196a
+                . $RUNSERVER_SCRIPT > $CONSOLE_LOG 2>&1 &
bb196a
+EOF
bb196a
+
bb196a
+	# Monitor every 1 seconds if the server has
bb196a
+	# recovered, until RECOVERY_TIMEOUT.
bb196a
+	t=0
bb196a
+	while [[ $t -le $OCF_RESKEY_start_timeout ]]
bb196a
+	do
bb196a
+		grep -s "Recovery complete." $CONSOLE_LOG > /dev/null 2>&1
bb196a
+		if [[ $? != 0 ]]
bb196a
+		then
bb196a
+			# The server has not completed the recovery. We need to continue to monitor the recovery
bb196a
+			# process.
bb196a
+			t=`expr $t + 1`
bb196a
+		else
bb196a
+			# The server has completed the recovery.
bb196a
+			ocf_log info "sybaseASE: ASE server '$OCF_RESKEY_server_name' started successfully."
bb196a
+			break
bb196a
+		fi
bb196a
+		sleep 1
bb196a
+	done
bb196a
+
bb196a
+	# If $t is larger than start_timeout, it means the ASE server cannot start in given time. Otherwise, it 
bb196a
+	# means the ASE server has started successfully.
bb196a
+	if [[ $t -gt $OCF_RESKEY_start_timeout ]]
bb196a
+	then
bb196a
+		# The server cannot start in specified time. We think the start is failed.
bb196a
+		ocf_log err "sybaseASE: Failed to start ASE server '$OCF_RESKEY_server_name'. Please check the server error log $CONSOLE_LOG for possible problems."
bb196a
+		return $OCF_ERR_GENERIC
bb196a
+	fi
bb196a
+
bb196a
+	ase_is_running
bb196a
+	if [ $? -ne 0 ]; then
bb196a
+		ocf_log err "sybaseASE: ase_start could not detect database initialized properly."
bb196a
+
bb196a
+		return $OCF_ERR_GENERIC
bb196a
+	fi
bb196a
+	ocf_log debug "sybaseASE: End 'ase_start' successfully."
bb196a
+	return $OCF_SUCCESS
bb196a
+}
bb196a
+
bb196a
+#############################################################################################
bb196a
+# Function name: ase_stop                                                                   #
bb196a
+# Parameter: None                                                                           #
bb196a
+# Return value:                                                                             #
bb196a
+#             0  SUCCESS                                                                    #
bb196a
+#             1  FAIL                                                                       #
bb196a
+# Description: This function is used to stop the ASE server in primary or secondary server. #
bb196a
+#############################################################################################
bb196a
+ase_stop()
bb196a
+{
bb196a
+	ocf_log debug "sybaseASE: Start 'ase_stop'"
bb196a
+
bb196a
+	# Check if the ASE server is still running.
bb196a
+	ase_is_running
bb196a
+	if [[ $? != 0 ]]
bb196a
+	then
bb196a
+		# The ASE server is not running. We need not to shutdown it.
bb196a
+		ocf_log info "sybaseASE: The dataserver $OCF_RESKEY_server_name is not running."
bb196a
+		return $OCF_SUCCESS
bb196a
+	fi
bb196a
+
bb196a
+	set_login_string
bb196a
+
bb196a
+	# Just in case things are hung, start a process that will wait for the
bb196a
+	# timeout period, then kill any remaining porcesses.  We'll need to
bb196a
+	# monitor this process (set -m), so we can terminate it later if it is
bb196a
+	# not needed.
bb196a
+	set -m
bb196a
+	kill_ase $OCF_RESKEY_shutdown_timeout &
bb196a
+	KILL_PID=$!     # If successful, we will also terminate watchdog process
bb196a
+
bb196a
+	# Run "shutdown with nowait" from isql command line to shutdown the server
bb196a
+	su $OCF_RESKEY_sybase_user -c ksh << EOF
bb196a
+		# set required SYBASE environment by running SYBASE.sh.
bb196a
+		. $OCF_RESKEY_sybase_home/SYBASE.sh
bb196a
+		# Run "shutdown with nowait" to shutdown the server immediately.
bb196a
+		(echo "use master" ; echo go ; echo "shutdown with nowait"; echo go) | \
bb196a
+		\$SYBASE/\$SYBASE_OCS/bin/isql $login_string -S$OCF_RESKEY_server_name -I$OCF_RESKEY_interfaces_file  &
bb196a
+EOF
bb196a
+
bb196a
+	sleep 5
bb196a
+
bb196a
+	# Check if the server has been shut down successfully
bb196a
+	t=0
bb196a
+	while [[ $t -lt $OCF_RESKEY_shutdown_timeout ]]
bb196a
+	do
bb196a
+		# Search "ueshutdown: exiting" in the server log. If found, it means the server has been shut down. 
bb196a
+		# Otherwise, we need to wait.
bb196a
+		tail $CONSOLE_LOG | grep "ueshutdown: exiting" > /dev/null 2>&1
bb196a
+		if [[ $? != 0 ]]
bb196a
+		then
bb196a
+			# The shutdown is still in processing. Wait...
bb196a
+			sleep 2
bb196a
+			t=`expr $t+2`
bb196a
+		else
bb196a
+			# The shutdown is success.
bb196a
+			ocf_log info "sybaseASE: ASE server '$OCF_RESKEY_server_name' shutdown with isql successfully."
bb196a
+			break
bb196a
+		fi
bb196a
+	done
bb196a
+
bb196a
+	# If $t is larger than shutdown_timeout, it means the ASE server cannot be shut down in given time. We need
bb196a
+	# to wait for the background kill process to kill the OS processes directly.
bb196a
+	if  [[ $t -ge $OCF_RESKEY_shutdown_timeout ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: Shutdown of '$OCF_RESKEY_server_name' from isql failed.  Server is either down or unreachable."
bb196a
+	fi
bb196a
+
bb196a
+	# Here, the ASE server has been shut down by isql command or killed by background process. We need to do
bb196a
+	# further check to make sure all processes have gone away before saying shutdown is complete. This stops the
bb196a
+	# other node from starting up the package before it has been stopped and the file system has been unmounted.
bb196a
+	
bb196a
+	# Get all processes ids from log file
bb196a
+	declare -a ENGINE_ALL=$(ase_all_pids)
bb196a
+
bb196a
+	typeset -i num_procs=${#ENGINE_ALL[@]}
bb196a
+
bb196a
+	# We cannot find any process id from log file. It may be because the log file is corrupted or be deleted.
bb196a
+	# In this case, we determine the shutdown is failed.
bb196a
+	if [[ "${ENGINE_ALL[@]}" = "" ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: Unable to find the process id from $CONSOLE_LOG."
bb196a
+		ocf_log err "sybaseASE: Stop ASE server failed."
bb196a
+		return $OCF_ERR_GENERIC
bb196a
+	fi
bb196a
+
bb196a
+	# Monitor the system processes to make sure all ASE related processes have gone away.
bb196a
+	while true
bb196a
+	do
bb196a
+		# To every engine process, search it in system processes list. If it is not in the
bb196a
+		# list, it means this process has gone away. Otherwise, we need to wait for it is
bb196a
+		# killed by background process.
bb196a
+		for i in ${ENGINE_ALL[@]}
bb196a
+		do
bb196a
+			ps -fu $OCF_RESKEY_sybase_user | awk '{print $2}' | grep $i | grep -v grep
bb196a
+			if [[ $? != 0 ]]
bb196a
+			then
bb196a
+				ocf_log debug "sybaseASE: $i process has stopped."
bb196a
+				c=0
bb196a
+				while (( c < $num_procs ))
bb196a
+				do
bb196a
+					if [[ ${ENGINE_ALL[$c]} = $i ]]
bb196a
+					then
bb196a
+						unset ENGINE_ALL[$c]
bb196a
+						c=$num_procs
bb196a
+					fi
bb196a
+					(( c = c + 1 ))	
bb196a
+				done
bb196a
+			fi
bb196a
+		done
bb196a
+		
bb196a
+		# To here, all processes should have gone away. 
bb196a
+		if [[ ${ENGINE_ALL[@]} = "" ]]
bb196a
+		then
bb196a
+			#
bb196a
+			# Looks like shutdown was successful, so kill the
bb196a
+			# script to kill any hung processes, which we started earlier.
bb196a
+			# Check to see if the script is still running.  If jobs
bb196a
+			# returns that the script is done, then we don't need to kill
bb196a
+			# it.
bb196a
+			#
bb196a
+			job=$(jobs | grep -v Done)
bb196a
+			if [[ ${job} != "" ]]
bb196a
+			then
bb196a
+				ocf_log debug "sybaseASE: Killing the kill_ase script."
bb196a
+
bb196a
+				kill -15 $KILL_PID > /dev/null 2>&1
bb196a
+			fi
bb196a
+			break
bb196a
+	        fi
bb196a
+		sleep 5
bb196a
+	done
bb196a
+
bb196a
+	ocf_log debug "sybaseASE: End 'ase_stop'."
bb196a
+
bb196a
+	return $OCF_SUCCESS
bb196a
+}
bb196a
+
bb196a
+####################################################################################
bb196a
+# Function name: ase_is_running                                                    #
bb196a
+# Parameter: None                                                                  #
bb196a
+# Return value:                                                                    #
bb196a
+#             0   ASE server is running                                            #
bb196a
+#             1   ASE server is not running or there are errors                    #
bb196a
+# Description: This function is used to check if the ASE server is still running . #
bb196a
+####################################################################################
bb196a
+ase_is_running()
bb196a
+{
bb196a
+	local PID
bb196a
+	local THREAD
bb196a
+	# If the error log doesn't exist, we can say there is no ASE is running.
bb196a
+	if [[ ! -f $CONSOLE_LOG ]]
bb196a
+	then
bb196a
+		ocf_log debug "could not find console log $CONSOLE_LOG"
bb196a
+		return $OCF_NOT_RUNNING
bb196a
+	fi
bb196a
+
bb196a
+	# The error log file exists. Check if the engine 0 is alive.
bb196a
+	PID=$(ase_engine0_process)
bb196a
+	if [ -n "$PID" ]; then
bb196a
+		kill -s 0 $PID > /dev/null 2>&1
bb196a
+		if [ $? -eq 0 ]; then
bb196a
+			# The engine 0 is running.
bb196a
+			ocf_log debug "Found engine 0 pid $PID to be running"
bb196a
+			return $OCF_SUCCESS
bb196a
+		fi
bb196a
+		# The engine 0 is not running.
bb196a
+		return $OCF_NOT_RUNNING
bb196a
+	fi
bb196a
+
bb196a
+	PID=$(ase_engine_threadpool_pid)
bb196a
+	THREAD=$(ase_engine0_thread)
bb196a
+	if [ -n "$PID" ] && [ -n "$THREAD" ]; then
bb196a
+		ps -AL | grep -q "${PID}[[:space:]]*${THREAD} "
bb196a
+		if [ $? -eq 0 ]; then
bb196a
+			# engine 0 thread is running
bb196a
+			ocf_log debug "Found engine 0 thread $THREAD in pid $PID to be running"
bb196a
+			return $OCF_SUCCESS
bb196a
+		fi
bb196a
+		# The engine 0 is not running.
bb196a
+		return $OCF_NOT_RUNNING
bb196a
+	fi
bb196a
+	return $OCF_ERR_GENERIC
bb196a
+}
bb196a
+
bb196a
+####################################################################################
bb196a
+# Function name: kill_ase                                                          #
bb196a
+# Parameter:                                                                       #
bb196a
+#             DELAY  The seconds to wait before killing the ASE processes. 0 means #
bb196a
+#                    kill the ASE processes immediately.                           #
bb196a
+# Return value: None                                                               #
bb196a
+#             1   ASE server is not running or there are errors                    #
bb196a
+# Description: This function is used to check if the ASE server is still running . #
bb196a
+####################################################################################
bb196a
+kill_ase()
bb196a
+{
bb196a
+	ocf_log debug "sybaseASE: Start 'kill_ase'."
bb196a
+
bb196a
+	DELAY=$1
bb196a
+
bb196a
+	# Wait for sometime before sending a kill signal.  
bb196a
+	t=0
bb196a
+        while [[ $t -lt $DELAY ]]
bb196a
+        do
bb196a
+     		sleep 1
bb196a
+		t=`expr $t+1`
bb196a
+        done
bb196a
+
bb196a
+	# Get the process ids from log file
bb196a
+	declare -a ENGINE_ALL=$(ase_all_pids)
bb196a
+
bb196a
+	# If there is no process id found in the log file, we need not to continue.
bb196a
+	if [[ "${ENGINE_ALL[@]}" = "" ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: Unable to find the process id from $CONSOLE_LOG."
bb196a
+		return $OCF_ERR_GENERIC
bb196a
+	fi
bb196a
+
bb196a
+	# Kill the datasever process(es)
bb196a
+	for pid in ${ENGINE_ALL[@]}
bb196a
+	do
bb196a
+		kill -9 $pid > /dev/null 2>&1
bb196a
+		if [[ $? != 0 ]]
bb196a
+		then
bb196a
+			ocf_log info "sybaseASE: kill_ase function did NOT find process $pid running."
bb196a
+		else
bb196a
+			ocf_log info "sybaseASE: kill_ase function did find process $pid running.  Sent SIGTERM."
bb196a
+		fi
bb196a
+	done
bb196a
+
bb196a
+	ocf_log debug "sybaseASE: End 'kill_ase'."
bb196a
+	return $OCF_SUCCESS
bb196a
+}
bb196a
+
bb196a
+#####################################################################################
bb196a
+# Function name: ase_status                                                         #
bb196a
+# Parameter:                                                                        #
bb196a
+#             0   Level 0 probe. In this level, we just check if engine 0 is alive  #
bb196a
+#             10  Level 10 probe. In this level, we need to probe if the ASE server #
bb196a
+#                 still has response.                                               #              
bb196a
+# Return value:                                                                     #
bb196a
+#             0   The server is still alive                                         #
bb196a
+#             1   The server is down                                                #
bb196a
+# Description: This function is used to check if the ASE server is still running.   #
bb196a
+#####################################################################################
bb196a
+ase_status()
bb196a
+{
bb196a
+	local rc
bb196a
+	ocf_log debug "sybaseASE: Start 'ase_status'."
bb196a
+
bb196a
+	# Step 1: Check if the engine 0 is alive
bb196a
+	ase_is_running
bb196a
+	rc=$?
bb196a
+	if [ $rc -ne 0 ]; then
bb196a
+		# ASE is down. Return fail to Pacemaker to trigger the failover process.
bb196a
+		ocf_log err "sybaseASE: ASE server is down."
bb196a
+		return $rc
bb196a
+	fi
bb196a
+
bb196a
+	# ASE process is still alive. 
bb196a
+	# Step2: If this is level 10 probe, We need to check if the ASE server still has response.
bb196a
+	if [[ $1 -gt 0 ]]
bb196a
+	then
bb196a
+		ocf_log debug "sybaseASE: Need to run deep probe."
bb196a
+		# Run deep probe
bb196a
+		deep_probe
bb196a
+		if [[ $? = 1 ]]
bb196a
+		then
bb196a
+			# Deep probe failed. This means the server has been down.
bb196a
+			ocf_log err "sybaseASE: Deep probe found the ASE server is down."
bb196a
+			return $OCF_ERR_GENERIC
bb196a
+		fi
bb196a
+	fi
bb196a
+
bb196a
+	ocf_log debug "sybaseASE: End 'ase_status'."
bb196a
+
bb196a
+	return $OCF_SUCCESS
bb196a
+}
bb196a
+
bb196a
+####################################################################################
bb196a
+# Function name: deep_probe                                                        #
bb196a
+# Parameter: None                                                                  #
bb196a
+# Return value:                                                                    #
bb196a
+#             0   ASE server is alive                                              #
bb196a
+#             1   ASE server is down                                               #
bb196a
+# Description: This function is used to run deep probe to make sure the ASE server #
bb196a
+#              still has response.                                                 #
bb196a
+####################################################################################
bb196a
+deep_probe()
bb196a
+{
bb196a
+	declare -i rv
bb196a
+	
bb196a
+	ocf_log debug "sybaseASE: Start 'deep_probe'."	
bb196a
+
bb196a
+	# Declare two temporary files which will be used in this probe.
bb196a
+	tmpfile1="$(mktemp /tmp/sybaseASE.1.XXXXXX)"
bb196a
+	tmpfile2="$(mktemp /tmp/sybaseASE.2.XXXXXX)"
bb196a
+	
bb196a
+	set_login_string
bb196a
+
bb196a
+	rm -f $tmpfile1
bb196a
+	rm -f $tmpfile2
bb196a
+
bb196a
+	# The login file is correct. We have gotten the login account and password from it.
bb196a
+	# Run isql command in background.
bb196a
+	su $OCF_RESKEY_sybase_user -c ksh << EOF
bb196a
+		# set required SYBASE environment by running SYBASE.sh.
bb196a
+		. $OCF_RESKEY_sybase_home/SYBASE.sh
bb196a
+		# Run a very simple SQL statement to make sure the server is still ok. The output will be put to
bb196a
+		# tmpfile1.
bb196a
+		(echo "select 1"; echo "go") |
bb196a
+		\$SYBASE/\$SYBASE_OCS/bin/isql $login_string -S$OCF_RESKEY_server_name -I$OCF_RESKEY_interfaces_file -t $OCF_RESKEY_deep_probe_timeout -e -o$tmpfile1 &
bb196a
+		# Record the isql command process id to temporary file. If the isql is hung, we need this process id
bb196a
+                # to kill the hung process.
bb196a
+		echo \$! > $tmpfile2	
bb196a
+EOF
bb196a
+	
bb196a
+	declare -i t=0
bb196a
+		
bb196a
+	# Monitor the output file tmpfile1.
bb196a
+	while [[ $t -lt $OCF_RESKEY_deep_probe_timeout ]]
bb196a
+	do
bb196a
+		# If the SQL statement is executed successfully, we will get the following output:
bb196a
+		# 1> select 1
bb196a
+		# 
bb196a
+		# -----------
bb196a
+		#           1
bb196a
+		# 
bb196a
+		# (1 row affected)
bb196a
+		# So, we determine if the execution is success by searching the keyword "(1 row affected)".
bb196a
+		grep "(1 row affected)" $tmpfile1
bb196a
+		if [[ $? = 0 ]]
bb196a
+		then
bb196a
+			ocf_log debug "sybaseASE: Deep probe sucess."
bb196a
+			break
bb196a
+		else
bb196a
+			sleep 1
bb196a
+			t=`expr $t+1`
bb196a
+		fi
bb196a
+	done	
bb196a
+
bb196a
+	# If $t is larger than deep_probe_timeout, it means the isql command line cannot finish in given time.
bb196a
+	# This means the deep probe failed. We need to kill the isql process manually.
bb196a
+	if [[ $t -ge $OCF_RESKEY_deep_probe_timeout ]]
bb196a
+	then
bb196a
+		ocf_log err "sybaseASE: Deep probe fail. The dataserver has no response."		
bb196a
+
bb196a
+		# Read the process id of isql process from tmpfile2
bb196a
+		pid=`cat $tmpfile2 | awk '{print $1}'`
bb196a
+
bb196a
+		rm -f $tmpfile1
bb196a
+		rm -f $tmpfile2
bb196a
+
bb196a
+		# Kill the isql process directly.
bb196a
+		kill -9 $pid
bb196a
+		return 1
bb196a
+	fi
bb196a
+
bb196a
+	rm -f $tmpfile1
bb196a
+	rm -f $tmpfile2
bb196a
+
bb196a
+	ocf_log debug "sybaseASE: End 'deep_probe'."
bb196a
+
bb196a
+	return 0
bb196a
+}
bb196a
+
bb196a
+#############################
bb196a
+# Do some real work here... #
bb196a
+#############################
bb196a
+case $1 in
bb196a
+	start)
bb196a
+		verify_all || exit $OCF_ERR_GENERIC
bb196a
+		ase_start
bb196a
+		exit $?
bb196a
+		;;
bb196a
+	stop)
bb196a
+		verify_all || exit $OCF_ERR_GENERIC
bb196a
+		ase_stop
bb196a
+		exit $?
bb196a
+		;;
bb196a
+	status | monitor)
bb196a
+		verify_all || exit $OCF_ERR_GENERIC
bb196a
+		ase_status $OCF_CHECK_LEVEL
bb196a
+		exit $?
bb196a
+		;;
bb196a
+	meta-data)
bb196a
+		meta_data
bb196a
+		exit $OCF_SUCCESS
bb196a
+		;;
bb196a
+	validate-all)
bb196a
+		verify_all
bb196a
+		exit $?
bb196a
+		;;
bb196a
+	*)
bb196a
+		echo "Usage: $SCRIPT {start|stop|monitor|status|validate-all|meta-data}"
bb196a
+		exit $OCF_ERR_UNIMPLEMENTED
bb196a
+		;;
bb196a
+esac
bb196a
+exit 0
bb196a
+