#!/bin/sh

#pragma ident "@(#)get_node_status.sh	1.7 95/04/06 SMI"

B=/opt/SUNWcluster/bin
E=/etc/opt/SUNWcluster
V=/var/opt/SUNWcluster
 

get_clustername() {
	if [ -f ${E}/conf/default_clustername ]; then
		cat ${E}/conf/default_clustername
	else
		echo ""
	fi
}

pdb_status() {
	state=`${B}/timed_run -q 10 ${B}/clustm getstate ${clustername} 2>&1`
	if [ $? -ne 0 ]; then
		# clustd not running - why did it fail?
		tmpdir=`${B}/cdbmatch env.tmpdir ${cdbfile}`
		DOINGSTOPFLAG=${tmpdir}/didstopprogs
		if [ -f ${DOINGSTOPFLAG} ]; then
			echo pdb: stopped
		else
			echo pdb: aborted
		fi
	else
		if [ -n "$state" -a "$state" = "end" ]; then
			echo pdb: included in running cluster
		else
			echo pdb: in_transition reconfiguration
		fi
	fi
			
}

cvm_status() {
	if [ ! -f /sbin/vxconfigd  -a  ! -f /usr/sbin/vxclust ]; then
		echo cvm: unknown - VX cluster utilities not installed
	elif [  -f /sbin/vxconfigd  -a ! -f /usr/sbin/vxclust ]; then
		echo cvm: unknown - VX cluster utilities incorrectly installed
	else
		CVM_MODE=`/usr/sbin/vxdctl -c mode | awk '{print $4}'` 
		if [ $CVM_MODE = 'inactive' ]; then
			echo cvm: not_in_shared_mode
		else 
			CVM_STATUS=`/usr/sbin/vxprint 2>&1 | egrep "SYNC|ATT"`
			if [ -z "$CVM_STATUS" ]; then
				echo cvm: up 
			else
				echo cvm: in_recovery
			fi
		fi
	fi
}
 
ora_status() {
	if [ -x ${B}/ora_check ]; then
		${B}/ora_check -e
	else
		echo ora: unknown
	fi
}


clustername=`get_clustername`

# First, look for the cluster state

if [ -n "$clustername" ]; then
	cdbfile=${E}/conf/${clustername}.cdb
	pdb_status
else
	echo pdb: unknown - no default clustername
fi

# then the cvm,
cvm_status

# and finally look for the oracle process

ora_status

