[BACK]Return to failsafe2 CVS log [TXT][DIR] Up to [Development] / failsafe / FailSafe / failsafe / init.d

File: [Development] / failsafe / FailSafe / failsafe / init.d / failsafe2 (download)

Revision 1.3, Fri Oct 26 09:26:59 2001 UTC (16 years ago) by lmb
Branch: MAIN
CVS Tags: HEAD
Changes since 1.2: +2 -2 lines

Fixing the path to resgroupAdmin to make a clean shutdown of FailSafe migrate
the resources cleanly.

#!/bin/sh
#                                                                         
# Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
# 
# This program is distributed in the hope that it would be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# 
# Further, this software is distributed without any warranty that it is
# free of the rightful claim of any third person regarding infringement
# or the like.  Any license provided herein, whether implied or
# otherwise, applies only to this software file.  Patent licenses, if
# any, provided herein do not apply to combinations of this program with
# other software, or any other product whatsoever.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write the Free Software Foundation,
# Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
# 
# Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
# Mountain View, CA 94043, or:
# 
# http://www.sgi.com 
# 
# For further information regarding this notice, see: 
# 
# http://oss.sgi.com/projects/GenInfo/NoticeExplan

#
# This script is used to start/stop Linux FailSafe  when a system boots
# or shuts down.
#
# NOTE: chkconfig on Redhat Linux requires these 2 lines: 
# chkconfig: 35 37 37
# description: failsafe daemon
#
# 35 => runlevels used  by cluster to start
#               0 = Halt level
#               1 = Single user mode
#               2 = Multi user without NFS
#               3 = Full multi users level
#               4 = Not used
#               5 = Full multi users level with X11 based login
#               6 = Reboot
#
# 37  => start priority
# 37  => stop priority

#ident "$Id: failsafe2,v 1.3 2001/10/26 09:26:59 lmb Exp $"


KILLALL=/usr/bin/killall
FIND=/usr/bin/find
RM=/bin/rm
XARGS=/usr/bin/xargs
LOGGER=/usr/bin/logger
CHKCONFIG=/usr/lib/failsafe/bin/fsconfig
IS_ON=${CHKCONFIG}
ECHO="/bin/echo -e"

ACTION=$1


# Linux FailSafe  variables
PATH=/usr/lib/failsafe/bin:$PATH
export PATH

COMM=/var/run/failsafe/comm
TMP=/var/run/failsafe/tmp/
SCRIPT_NAME=failsafe
CURR_SCRIPT_NAME=`/bin/basename $0`
SIGTERM_TMOUT=10;

FSD2=ha_fsd
CMOND=cmond
CMON_START="/usr/lib/failsafe/bin/cmon_ctrl start -r -g"
CMON_STOP="/usr/lib/failsafe/bin/cmon_ctrl stop -r -f -g"
CLUSTER_IPADDR_GRP=ip_addresses
CLUSTER_HAINFRA_GRP=cluster_hainfra
CLUSTER_FAILSAFE_GRP=cluster_failsafe


################################
# killall_timeout function
#
# Emulate the killall -k on IRIX:
# Sends a SIGTERM to a process. If process is not killed,
# waits for SIGTERM_TMOUT seconds and then sends SIGKILL signal.
#
# Syntax: killall_timeout -k tout process_name
#
################################
function killall_timeout()
{
  count=0

  # First, try to send a TERM signal to the process
  ${KILLALL} -TERM $3 > /dev/null 2>&1

  # give timeout seconds to the process to die
  # check every seconds if process is down
  while [ $count -lt $2 ]
  do
	# check if the process is still up
	${KILLALL} -0 $3 > /dev/null 2>&1	
	if [ $? -ne 0 ]
	then
		return 0
	fi
	
	# process is not dead, wait one more sec
	count=`expr $count + 1`
	sleep 1
  done

  # finally, if process is not dead, send a KILL signal
  ${KILLALL} -KILL $3 > /dev/null 2>&1
}


################################
# fs2 function
#
# Start | Stop failsafe daemons
#
################################
fs2()
{
    #
    # Check if this script is being run by hand.
    # This script is not expected to be used for starting and stopping
    # FailSafe services on a node
    #
    if [ ${SCRIPT_NAME} = ${CURR_SCRIPT_NAME} ]; then
	echo "Please use cluster_mgr command or Linux FailSafe GUI"
	echo "to start/stop FailSafe services in a node."
	exit 1;
    fi
    case ${ACTION} in
    'start')
	if ${IS_ON} failsafe; then

	    #
	    # Cleanup any comm files and cluster tmp directory.
	    #
	    ${FIND} ${COMM} -name 'ipc*' -print | ${XARGS} ${RM} -f
	    ${FIND} ${COMM} \( -name 'cmsd*' -o -name 'gcs*' -o -name 'srm*' \
 			-o -name 'ifd*' -o -name 'fsd*' \) -print | ${XARGS} \
			${RM} -f
	    ${FIND} ${TMP} -type f -print | ${XARGS} ${RM} -f

	    #
	    # Startup Cluster HA Daemons and FailSafe
	    #
	    # only print next line to SYSLOG
	    ${LOGGER} "Starting Failsafe"

	    $ECHO "Starting Failsafe\c"

	    # Starting FailSafe agents
	    ${CMON_START} ${CLUSTER_IPADDR_GRP} > /dev/null 2>&1;
	    if [ $? -ne 0 ]; then
		echo "FailSafe agents could not be started"
		echo "Check if cluster processes are running"
		exit 1;
	    fi

	    # Starting Cluster HA processes
	    ${CMON_START} ${CLUSTER_HAINFRA_GRP} > /dev/null 2>&1;
	    if [ $? -ne 0 ]; then
		echo "HA processes could not be started"
		echo "Check if cluster processes are running"
		exit 1;
	    fi

	    # Starting FailSafe process
	    ${CMON_START} ${CLUSTER_FAILSAFE_GRP} > /dev/null 2>&1;
	    if [ $? -ne 0 ]; then
		echo "FailSafe process could not be started"
		echo "Check if cluster processes are running"
		exit 1;
	    fi

	    $ECHO "."
	fi
	;;

    'stop')
	#
	# Move resource groups online on this node to other cluster nodes
	#
	${KILLALL} -0 ${FSD2} > /dev/null 2>&1;
	if [ $? -eq 0 ]; then
	    # Stop all Failsafe daemons
	    /usr/lib/sysadm/privbin/resgroupAdmin \
		_RESOURCE_GROUP_ACTION=shutdown_node _CLUSTER=_LOOKMEUP
	    if [ $? -ne 0 ]; then
		${LOGGER} "Failsafe: Unable to release resource groups"
		echo "Failsafe: Unable to release resource groups"
	    fi
	fi

	#
	# Stop all FailSafe related process
	#

	# Check if cmond process is running.
        ${KILLALL} -0 ${CMOND} > /dev/null 2>&1
        if [ $? -eq 0 ]; then

	    # Stopping FailSafe process
	    ${CMON_STOP} ${CLUSTER_FAILSAFE_GRP} > /dev/null 2>&1;
	    if [ $? -ne 0 ]; then
		echo "FailSafe process could not be stopped"
		echo "Check if cluster processes are running"
		exit 1;
	    fi

	    # Stopping Cluster HA processes
	    ${CMON_STOP} ${CLUSTER_HAINFRA_GRP} > /dev/null 2>&1;
	    if [ $? -ne 0 ]; then
		echo "HA processes could not be stopped"
		echo "Check if cluster processes are running"
		exit 1;
	    fi

	    # Stopping FailSafe agents
	    ${CMON_STOP} ${CLUSTER_IPADDR_GRP} > /dev/null 2>&1;
	    if [ $? -ne 0 ]; then
		echo "FailSafe agents could not be stopped"
		echo "Check if cluster processes are running"
		exit 1;
	    fi
        else 
	    echo "Killing FailSafe processes."
	    killall_timeout -k ${SIGTERM_TMOUT} ha_cmsd
	    killall_timeout -k ${SIGTERM_TMOUT} ha_fsd
	    killall_timeout -k ${SIGTERM_TMOUT} ha_gcd
	    killall_timeout -k ${SIGTERM_TMOUT} ha_srmd;
	    killall_timeout -k ${SIGTERM_TMOUT} ha_ifd;
	fi

	#
	# Cleanup any comm files and cluster tmp directory
	#
	${FIND} ${COMM} -name 'ipc*' -print | ${XARGS} ${RM} -f
	${FIND} ${COMM} \( -name 'cmsd*' -o -name 'gcs*' -o -name 'srm*' \
 			-o -name 'ifd*' -o -name 'fsd*' \) -print | ${XARGS} \
			    ${RM} -f
	${FIND} ${TMP} -type f  -print | ${XARGS} ${RM} -f

	sync
	;;

    *)
	echo Invalid argument = ${ACTION}
	echo Failsafe NOT started.
	echo "Usage: $0 [start|stop]"
	exit 1
	;;
    esac
}


#
# If $1 is a valid process, then exit
#
fs2_daemon_is_running()
{
    ${KILLALL} -0 $1 > /dev/null 2>&1
    if [ $? -eq 0 ]; then
	${LOGGER} -s "Failsafe processes already running";
	${LOGGER} -s "Stop Failsafe first: /etc/rc.d/init.d/failsafe stop"
	exit 1
    fi
}


case ${ACTION} in
    'start')
	fs2
	;;

    'stop')
	fs2
	;;

    *)
	echo Invalid argument = ${ACTION}
	echo FailSafe NOT started.
	echo "Usage: $0 [start|stop]"
	exit 1
	;;
esac