#
# Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

SCLOGGER=/usr/cluster/lib/sc/scds_syslog
PKG=SUNWscmqs.mgr
METHOD=`basename $0`
DS_BASEDIR=`dirname $0`
LOGFILE=/var/tmp/${RESOURCE}_logfile
TASK_COMMAND=""
RESOURCE_PROJECT_NAME=""
PATTERN="\<$QMGR\>|\<m$QMGR\>"
SCHA_RESOURCEGROUP_GET=/usr/cluster/bin/scha_resourcegroup_get
SCHA_RESOURCE_GET=/usr/cluster/bin/scha_resource_get
SCHA_CLUSTER_GET=/usr/cluster/bin/scha_cluster_get

STOP_TIMEOUT=`$SCHA_RESOURCE_GET -O Stop_timeout \
		-R $RESOURCE -G $RESOURCEGROUP`

SYSLOG_FACILITY=`$SCHA_CLUSTER_GET -O SYSLOG_FACILITY`

syslog_tag()
{
	#
        # Data Service message format
	#

	$SET_DEBUG

        print "SC[${PKG:-??}.${METHOD:-??}]:${RESOURCEGROUP:-??}:${RESOURCE:-??}"
}

scds_syslog()
{

	#
        # Log a message
	#

        $SET_DEBUG

        $SCLOGGER "$@" &
}

debug_message()
{
	#
        # Output a debug message to syslog if required
	#

	if [ "$DEBUG" = "$RESOURCE" -o "$DEBUG" = "ALL" ]
	then
		SET_DEBUG="set -x"

		DEBUG_TEXT=$1

               	scds_syslog -p daemon.debug -t $(syslog_tag) -m \
                     	"%s" "$DEBUG_TEXT"
	else
		SET_DEBUG=
	fi
}

log_message()
{
	#
        # Output a message to syslog as required
	#

	debug_message "Function: log_message - Begin"
	$SET_DEBUG

	if [ -s "${LOGFILE}" ]
	then
		PRIORITY=$1
		HEADER=$2

		if [ "${PRIORITY}" = "error" ]
		then
        		echo "The following $QMGR processes are still running" >> $LOGFILE
			ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' >> $LOGFILE
		fi

                #
                # Ensure the while loop only reads a closed file
                #

                strings ${LOGFILE} > ${LOGFILE}.copy

        	while read MSG_TXT
               	do
               		scds_syslog -p daemon.${PRIORITY} -t $(syslog_tag) -m \
                       		"%s - %s" \
				"${HEADER}" "${MSG_TXT}"
                done < ${LOGFILE}.copy

		su ${USERID} -c "cat /dev/null > $LOGFILE" > /dev/null
		cat /dev/null > ${LOGFILE}.copy
	fi

	debug_message "Function: log_message - End"
}

validate_options()
{
        #
        # Ensure all options are set
        #

        for i in RESOURCE RESOURCEGROUP QMGR CLEANUP USERID
        do
               	case $i in
               		RESOURCE)
                        if [ -z $RESOURCE ]; then
                        	logger -p daemon.err \
                        	"ERROR: `basename $0` Option -R not set"
                        	exit 1
                        fi;;

                       	RESOURCEGROUP)
                        if [ -z $RESOURCEGROUP ]; then
                        	logger -p daemon.err \
                        	"ERROR: `basename $0` Option -G not set"
                        	exit 1
                        fi;;

                       	QMGR)
                        if [ -z $QMGR ]; then
                        	logger -p daemon.err \
                        	"ERROR: `basename $0` Option -Q not set"
                        	exit 1
                        fi;;

                       	CLEANUP)
                        if [ -z $CLEANUP ]; then
				CLEANUP=YES
                        fi;;

                       	USERID)
                        if [ -z $USERID ]; then
				USERID=mqm
                        fi;;
                esac
        done
}

validate()
{
	#
	# Validate User ID mqm
	#

	debug_message "Function: validate - Begin"
	$SET_DEBUG

	rc_validate=0

	if cat /etc/passwd | awk -F: '{print $1}' | grep -w mqm > /dev/null
	then
		debug_message "Validate - User mqm exists"
	else
		rc_validate=1

		scds_syslog -p daemon.error -t $(syslog_tag) -m \
		"Validate - User mqm does not exist"
	fi

	#
	# Validate Group mqm and user root exists within group mqm
	#

	if cat /etc/group | awk -F: '{print $1}' | grep -w mqm > /dev/null
	then
		debug_message "Validate - Group mqm exists"

		mqver=`pkginfo -l mqm | grep VERSION | awk '{print $2}' | awk -F. '{print $1$2}'`
		
		if [ "$mqver" -lt "53" ]
		then
			if cat /etc/group | awk -F: '{ if ($1 == "mqm") print $4}' | grep -w root > /dev/null
			then
				debug_message "Validate - Group mqm exists with user root"
			else
				rc_validate=1
			
				scds_syslog -p daemon.error -t $(syslog_tag) -m \
				"Validate - User root is not a member of group mqm"
			fi
		fi
	else
		rc_validate=1

		scds_syslog -p daemon.error -t $(syslog_tag) -m \
		"Validate - Group mqm does not exist"
	fi

	#
	# Validate $USERID
	#
	
	if [ "$USERID" = "mqm" ]
	then
		debug_message "Validate - Userid is mqm"
	else
		pgroup=`grep -w $USERID /etc/passwd | awk -F: '{print $4}'`

		if [ ! -z $pgroup ]
		then
			if cat /etc/group | awk -F: '{ if ($1 == "mqm") print $3}' | grep -w $pgroup > /dev/null
			then
				debug_message "Validate - Primary group for userid $USERID is mqm"
			else
				if cat /etc/group | awk -F: '{ if ($1 == "mqm") print $4}' | grep -w $USERID > /dev/null
				then
					debug_message "Validate - Secondary group for userid $USERID is mqm"
				else
					rc_validate=1

					scds_syslog -p daemon.error -t $(syslog_tag) -m \
					"Validate - Userid $USERID is not a member of group mqm"
				fi
			fi
		else
			rc_validate=1

			scds_syslog -p daemon.error -t $(syslog_tag) -m \
			"Validate - Userid $USERID is not a valid userid"
		fi
	fi
	
	#
	# Validate that /opt/mqm and /var/mqm exist
	#

	if [ -d /opt/mqm -a -d /var/mqm ]
	then
		debug_message "Validate - WebSphere MQ file systems ok"
	else
		rc_validate=1
		
		scds_syslog -p daemon.error -t $(syslog_tag) -m \
		"Validate - WebSphere MQ file systems not defined"
	fi

	#
	# Validate $CLEANUP
	#
	
	case "${CLEANUP}" in
		YES|NO)		debug_message "Validate - CLEANUP=$CLEANUP"
                                ;;
		*)		rc_validate=1

                                scds_syslog -p daemon.error -t $(syslog_tag) -m \
                                        "Validate - CLEANUP=%s is invalid" \
                                        "$CLEANUP"
                                ;;
        esac

	debug_message "Function: validate - End"
	$SET_DEBUG
}

standard_resource_get()
{
        debug_message "Function: standard_resource_get - Begin"
        $SET_DEBUG

        PROPERTY=$1

        ${SCHA_RESOURCE_GET} -R ${RESOURCE} -G ${RESOURCEGROUP} -O ${PROPERTY}

        s1=$?

        if [ "${s1}" -ne 0 ]; then
                debug_message "standard_resource_get - Get property ${PROPERTY} rc<${s1}>, ignore if SC3.0"
        fi

        debug_message "Function: standard_resource_get - End"
        return ${s1}
}

standard_resourcegroup_get()
{
        debug_message "Function: standard_resourcegroup_get - Begin"
        $SET_DEBUG

        PROPERTY=$1

        ${SCHA_RESOURCEGROUP_GET} -R ${RESOURCE} -G ${RESOURCEGROUP} -O ${PROPERTY}

        s1=$?

        if [ "${s1}" -ne 0 ]; then
                debug_message "standard_resource_get - Get property ${PROPERTY} rc<${s1}>, ignore if SC3.0"
        fi

        debug_message "Function: standard_resourcegroup_get - End"

        return ${s1}
}

srm_function()
{
        debug_message "Function: srm_function - Begin"
        $SET_DEBUG

        USER=$1
   
        # 
        # If Solaris 8 just return
        #

        if [ `/usr/bin/uname -r` = "5.8" ];
        then
                return 0
        fi

        #
        # Retrieve RESOURCE_PROJECT_NAME
        #

        RESOURCE_PROJECT_NAME=`standard_resource_get RESOURCE_PROJECT_NAME`

        #
        # Retrieve RG_PROJECT_NAME if RESOURCE_PROJECT_NAME is not set
        #

        if [ -z "${RESOURCE_PROJECT_NAME}" ]; then

                RESOURCE_PROJECT_NAME=`standard_resourcegroup_get RG_PROJECT_NAME`
        fi

        #
        # Return if no projects are defined
        #

        if [ -z "${RESOURCE_PROJECT_NAME}" ]; then
                return 0
        fi

        #
        # Validate that $USER belongs to the project defined by
        # ${RESOURCE_PROJECT_NAME}
        #

        PROJ_MEMBER=`/usr/bin/projects ${USER} | /usr/bin/grep -w ${RESOURCE_PROJECT_NAME}`

        if [ -z "${PROJ_MEMBER}" ];
        then
             scds_syslog -p daemon.error -t $(syslog_tag) -m \
                        "Validate - The user %s does not belongs to project %s" \
                        "${USER}" "${RESOURCE_PROJECT_NAME}" 
                return 1
        else
                debug_message "srm_function - User ${USER} belongs to project ${RESOURCE_PROJECT_NAME}"
        fi

        #
        # Set TASK_COMMAND
        #

        TASK_COMMAND="/usr/bin/newtask -p ${RESOURCE_PROJECT_NAME}"

        debug_message "Function: srm_function - End"

        return 0
}

create_dummy_process()
{
	debug_message "Function: create_dummy_process - Begin"
	$SET_DEBUG

	DUMMY_PROCESS="/tmp/${RESOURCE}_${RESOURCEGROUP}_dummy.csh"

	cat > ${DUMMY_PROCESS} <<-EOF
	#!/bin/csh

	while (1)
		sleep 3600
	end
	EOF

  	/bin/chmod 755 ${DUMMY_PROCESS}

  	${DUMMY_PROCESS} &

	scds_syslog -p daemon.notice -t $(syslog_tag) -m \
		"Create_dummy_process - WebSphere MQ %s was manually started" \
		"${QMGR}"

	debug_message "Function: create_dummy_process - End"
}


start_qmgr()
{
	#
        # Start the Queue Manager
	#

	debug_message "Function: start_qmgr - Begin"
	$SET_DEBUG

	srm_function ${USERID}

	# Allow for multiple databases that can be included within global units of work.

	SC3_XARM=

	if [ ! -z $DB2INSTANCE ]; then
		SC3_XARM="env DB2INSTANCE=$DB2INSTANCE"
	fi

	if [ ! -z $ORACLE_HOME ]; then
		SC3_XARM="$SC3_XARM env ORACLE_HOME=$ORACLE_HOME"
	fi

	if [ ! -z $ORACLE_SID ]; then
		SC3_XARM="$SC3_XARM env ORACLE_SID=$ORACLE_SID"
	fi

	if getent passwd ${USERID} | awk -F: '{print $7}' | grep csh > /dev/null
	then
		su - ${USERID} -c "$TASK_COMMAND env SC3_COMMAND=${START_COMMAND} $SC3_XARM strmqm ${QMGR} >& ${LOGFILE}" > /dev/null
		rc_strmqm=$?
	else
		su - ${USERID} -c "$TASK_COMMAND env SC3_COMMAND=${START_COMMAND} $SC3_XARM strmqm ${QMGR} >${LOGFILE} 2>&1" > /dev/null
		rc_strmqm=$?
	fi

	debug_message "Function: start_qmgr - End"
}

orderly_stop_qmgr()
{
	#
	# Orderly stop of services
	#

	debug_message "Function: orderly_stop_qmgr - Begin"
	$SET_DEBUG
	
	srm_function ${USERID}

        for func in stop_qmgr_immediate \
                    stop_qmgr_preemptive \
                    cleanup_qmgr
        do
		case $func in
			stop_qmgr_immediate)	((FORCE_TIME=$STOP_TIMEOUT *40/100));;
			stop_qmgr_preemptive)	((FORCE_TIME=$STOP_TIMEOUT *30/100));;
			cleanup_qmgr)		((FORCE_TIME=$STOP_TIMEOUT *5/100));;
                esac

		LOOP_TIME=$FORCE_TIME

		if  ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' > /dev/null
		then
                	$func
		fi

		# Test if any ${QMGR} pids are still running

                while (( $LOOP_TIME > 0 ))
                do
			if ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' > /dev/null
                        then
                                sleep 1
                                LOOP_TIME=`expr $LOOP_TIME - 1`
                        else
                                break
                        fi

			# For stop_qmgr_immediate & stop_qmgr_preemptive
			# bail out if we've lost amqzxma0
                                                                                                              
			if [ "$func" = "stop_qmgr_immediate" -o  "$func" = "stop_qmgr_preemptive" ]
			then
				if ! ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' |\
					grep -w amqzxma0 > /dev/null
				then
					break
				fi
			fi
                done

                # Test if we broke out of the loop or the time
		# allocated for the function has expired.

		if ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' > /dev/null
                then
			# As we process stop_qmgr_immediate and
			# stop_qmgr_preemptive, output any
			# messages that have been collected

			log_message notice endmqm
			continue
		else
                        # Break out of running all the functions
			log_message notice endmqm
                        break
                fi
	done

	debug_message "Function: orderly_stop_qmgr - End"
}

stop_qmgr_immediate()
{
	#
	# Stop immediate the Queue Manager
	#

	debug_message "Function: stop_qmgr_immediate - Begin"
	$SET_DEBUG

	# Cleanup any runmqsc prompts 

	for i in `ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' |\
		 grep -w runmqsc | awk '{print $1}'`
	do
		kill -9 $i
		debug_message "MQSC command prompt (runmqsc) for $QMGR found and killed"
	done

	# Allow for multiple databases that can be included within global units of work.

	SC3_XARM=

	if [ ! -z $DB2INSTANCE ]; then
		SC3_XARM="env DB2INSTANCE=$DB2INSTANCE"
	fi

	if [ ! -z $ORACLE_HOME ]; then
		SC3_XARM="$SC3_XARM env ORACLE_HOME=$ORACLE_HOME"
	fi

	if [ ! -z $ORACLE_SID ]; then
		SC3_XARM="$SC3_XARM env ORACLE_SID=$ORACLE_SID"
	fi

	#
	# See IBM Technote 1159674 for MQCHL_NO_TERM_FFST 
	#
	# Turns off FFSTs when a channel job dies before the channel status
	# table is updated. It will not affect any other FDCs being generated
	# 

	if getent passwd ${USERID} | awk -F: '{print $7}' | grep csh > /dev/null
	then
		su - ${USERID} -c "$TASK_COMMAND env MQCHL_NO_TERM_FFST=1 env SC3_COMMAND=${STOP_COMMAND} $SC3_XARM endmqm -i ${QMGR} >& ${LOGFILE} &" > /dev/null
	else
		su - ${USERID} -c "$TASK_COMMAND env MQCHL_NO_TERM_FFST=1 env SC3_COMMAND=${STOP_COMMAND} $SC3_XARM endmqm -i ${QMGR} >${LOGFILE} 2>&1 &" > /dev/null
	fi

	debug_message "Function: stop_qmgr_immediate - End"
}

stop_qmgr_preemptive()
{
	#
	# Stop preemptive the Queue Manager
	#

	debug_message "Function: stop_qmgr_preemptive - Begin"
	$SET_DEBUG

	# Allow for multiple databases that can be included within global units of work.

	SC3_XARM=

	if [ ! -z $DB2INSTANCE ]; then
		SC3_XARM="env DB2INSTANCE=$DB2INSTANCE"
	fi

	if [ ! -z $ORACLE_HOME ]; then
		SC3_XARM="$SC3_XARM env ORACLE_HOME=$ORACLE_HOME"
	fi

	if [ ! -z $ORACLE_SID ]; then
		SC3_XARM="$SC3_XARM env ORACLE_SID=$ORACLE_SID"
	fi

	#
	# See IBM Technote 1159674 for MQCHL_NO_TERM_FFST 
	#
	# Turns off FFSTs when a channel job dies before the channel status
	# table is updated. It will not affect any other FDCs being generated
	# 

	if getent passwd ${USERID} | awk -F: '{print $7}' | grep csh > /dev/null
	then
		su - ${USERID} -c "$TASK_COMMAND env MQCHL_NO_TERM_FFST=1 env SC3_COMMAND=${STOP_COMMAND} $SC3_XARM endmqm -p ${QMGR} >& ${LOGFILE} &" > /dev/null
	else
		su - ${USERID} -c "$TASK_COMMAND env MQCHL_NO_TERM_FFST=1 env SC3_COMMAND=${STOP_COMMAND} $SC3_XARM endmqm -p ${QMGR} >${LOGFILE} 2>&1 &" > /dev/null
	fi

	debug_message "Function: stop_qmgr_preemptive - End"
}

cleanup_qmgr()
{
	#
	# Kill the Queue Manager
	#

	debug_message "Function: cleanup_qmgr - Begin"
	$SET_DEBUG

	for pid in amqc amqpcsea amqhasmx amqharmx amqzllp0 \
		amqzlaa0 runmqchi amqzxma0 amqrrmfa runmqtrm runmqlsr
	do
		for i in `ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' |\
			 grep -w $pid | awk '{print $1}'`
		do
			kill -9 $i
		done
	done

	# Cleanup any other pids that may have been missed
	for i in `ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' | awk '{print $1}'`
	do
		kill -9 $i
	done

	scds_syslog -p daemon.notice -t $(syslog_tag) -m \
	"All WebSphere MQ ($QMGR}) processes stopped" 
	
	debug_message "Function: cleanup_qmgr - End"

	break
}

cleanup_ipc()
{
	#
	# Cleanup_ipc only if requested to do so when the resource was registered
	#

	debug_message "Function: cleanup_ipc - Begin"
	$SET_DEBUG

	#
	# Cleanup any IPC shared memory segments however only if 
	#
	#	- The shared memory segment(s) are owned by 
	#		CREATOR=mqm and CGROUP=mqm
	#	- The shared memory has no attached processes
	#	- The CPID and LPID processes are not running
	#

	sleep 2

	debug_message "IPC Status BEFORE removal of non-attached segments created by user mqm"

	if [ "$DEBUG" = "$RESOURCE" -o "$DEBUG" = "ALL" ]
 	then
		ipcs -mcopb > $LOGFILE
		# Logger is used simply to keep the output compact
		logger -f $LOGFILE -p $SYSLOG_FACILITY.debug -t $(syslog_tag)
	fi

	flag=

	for shmid in `ipcs -mcopb | awk ' \
		{if (NF == 12 && $7 == "mqm" && $8 == "mqm" && $9 == 0 ) print $2; else \
	 	 if (NF == 11 && $6 == "mqm" && $7 == "mqm" && $8 == 0 ) print $1 }'`
	do
		shmid=`echo $shmid | tr 'm' ' '`

		for i in $shmid
		do 
			# Check if the CPID is running

			cpid=`ipcs -mp | grep -w $i | awk '{if (NF == 8) print $7; else \
				if (NF == 7 ) print $6 }'` 
				
			cpid=`echo $cpid | tr 'm' ' '`

			if [ ! -z "$cpid" ]
			then
				if ! ps -p $cpid > /dev/null
				then
					debug_message "WebSphere MQ SHMID: $shmid - CPID: ${cpid} not running"

					# Check if the LPID is running
				
					lpid=`ipcs -mp | grep -w $i | awk '{if (NF == 8) print $8; else \
						if (NF == 7 ) print $7 }'` 

					lpid=`echo $lpid | tr 'm' ' '`

					if [ ! -z "$lpid" ]
					then
						if ! ps -p $lpid > /dev/null
						then 
							debug_message "WebSphere MQ SHMID: $shmid - LPID: ${lpid} not running"

							su mqm -c "ipcrm -m `echo $shmid | tr 'm' ' '`"
							debug_message "WebSphere MQ SHMID: $shmid - removed"
		
							flag=set
						else
							debug_message "WebSphere MQ SHMID: $shmid - LPID ${lpid} running"
							ps -o pid,args -p $lpid > $LOGFILE
							log_message debug "WebSphere MQ SHMID: $shmid"
							debug_message "WebSphere MQ SHMID: $shmid - NOT removed, pid $lpid is probably ending but hasn't ended yet"
						fi
					fi
				else
					debug_message "WebSphere MQ SHMID: $shmid - CPID ${cpid} running"
					ps -o pid,args -p $cpid > $LOGFILE
					log_message debug "WebSphere MQ SHMID: $shmid"
					debug_message "WebSphere MQ SHMID: $shmid - NOT removed, pid $cpid is probably ending but hasn't ended yet"
				fi
			fi
		done
	done

	if [ ! -z "$flag" ]
	then
		scds_syslog -p daemon.notice -t $(syslog_tag) -m \
			"All WebSphere MQ non-attached IPC shared memory segments removed" 
	fi

	debug_message "IPC Status AFTER removal of non-attached segments created by user mqm"

	if [ "$DEBUG" = "$RESOURCE" -o "$DEBUG" = "ALL" ]
        then
		ipcs -mcopb > $LOGFILE
		# Logger is used simply to keep the output compact
		logger -f $LOGFILE -p $SYSLOG_FACILITY.debug -t $(syslog_tag)
	fi

	debug_message "Function: cleanup_ipc - End"
}

stop_runmqlsr()
{
	#
	# Stop the Listener program (runmqlsr)
	#
	
	debug_message "Function: stop_runmqlsr - Begin"
	$SET_DEBUG
	
	if ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' |\
		grep -w runmqlsr > /dev/null 
	then
		for pid in `ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' |\
			grep -w runmqlsr | awk '{print $1}'`
		do
			kill -9 $pid
		done
	fi

	debug_message "Function: stop_runmqlsr - End"
}

check_start()
{
	# 
	# Check if the Queue Manager is being started
	#

	debug_message "Function: check_start - Begin"
	$SET_DEBUG

	rc_check_start=0

	if pgrep -fl start-qmgr | eval /usr/xpg4/bin/grep -E '$PATTERN' > /dev/null
	then
		rc_check_start=1
	fi
	
	debug_message "Function: check_start - End"
}

check_qmgr() 
{
	#
	# Test Queue Manager Status
	# 
	# create_tdq does the following
	# 	Connect to ${QMGR}
	#	Open a temporary dynamic queue
	#	Put a test message to that queue
	#	Disconnect from ${QMGR}
	#

	debug_message "Function: check_qmgr - Begin"
	$SET_DEBUG

	# Here we test for the main Queue Manager processes
	# before we try create_tdq. 

	rc_check_qmgr_pids=

        # Check for the main processes

        for pid in amqzxma0 amqhasmx amqzllp0
        do
		if ps -u mqm -o pid,args | eval /usr/xpg4/bin/grep -E '$PATTERN' |\
			grep -w $pid > /dev/null
        	then
        		rc=0
        	else
        		rc=1
        	fi

        	rc_check_qmgr_pids=$rc_check_qmgr_pids$rc
        done

	if [ "$rc_check_qmgr_pids" != 000 ]
	then
		rc_check_qmgr=1
	else
        	check_qmgr_status=`${DS_BASEDIR}/create_tdq ${QMGR}`

		rc_check_qmgr=$?

		if [ "$rc_check_qmgr" != 0 ]
		then 
                	scds_syslog -p daemon.notice -t $(syslog_tag) -m \
                		"check_qmgr - <%s>" \
				"${check_qmgr_status}"
		fi
	fi
	
	debug_message "Function: check_qmgr - End"
}

set_status()
{
	#
        # Set appropriate resource status
	#

	debug_message "Function: set_status - Begin"
	$SET_DEBUG

        STATUS_TYPE=$1

        scha_resource_setstatus -R $RESOURCE -G $RESOURCEGROUP -s $STATUS_TYPE

        rc_scha_resource_setstatus=$?

        if [ "$rc_scha_resource_setstatus" != 0 ]
	then
                scds_syslog -p daemon.error -t $(syslog_tag) -m \
                "set_status - rc<%s>  type<%s>" \
                "${rc_scha_resource_setstatus}" "${STATUS_TYPE}"
        fi

	debug_message "Function: set_status - End"
}
