#! /bin/sh # # $Id: cluster_stop.sh,v 6.13.30.5 2006/04/26 19:32:49 castrv Exp $ Copyright (c) 2000-2005 EMC Corporation # # # Copyright (c) 2000-2005 EMC Corporation. # # All rights reserved. This is an UNPUBLISHED work, and # comprises proprietary and confidential information of EMC. # Unauthorized use, disclosure, and distribution are strictly # prohibited. Use, duplication, or disclosure of the software # and documentation by the U.S. Government is subject to # restrictions set forth in a license agreement between the # Government and EMC or other written agreement specifying # the Government's rights to use the software and any applicable # FAR provisions, such as FAR 52.227-19. # ***************************************************************** # * * # * Copyright (c) Digital Equipment Corporation, 1991, 1997 * # * Copyright (c) EMC Corporation., 1990-2006 * # * * # * All rights reserved. Unpublished rights reserved under * # * the copyright laws of the United States. * # * * # * The software contained on this media is proprietary to * # * and embodies the confidential technology of Digital * # * Equipment Corporation. Possession, use, duplication or * # * dissemination of the software and media is authorized only * # * pursuant to a valid written license from Digital Equipment * # * Corporation. * # * * # * RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure * # * by the U.S. Government is subject to restrictions as set * # * forth in Subparagraph (c)(1)(ii) of DFARS 252.227-7013, * # * or in FAR 52.227-19, as applicable. * # * * # ***************************************************************** # # Within clustering environments, this script is provided to enable # the platform's clustering management software to shut down a # NetWorker server for whatever reason, including service failover. # The server must be set up as a data service within the cluster. # # There are two things necessary for the failover mechanism to # complete properly: # # 1. All NetWorker services need to be properly shutdown. This is # done with the NetWorker shutdown script, ${NSR_STOP}. # # 2. After shutdown, the NetWorker database needs to be local to # the given physical host, so that nsrexecd may continue to run # within the clustering environment. To do this, /nsr is reset # to point to a local NSR database, defined by ${NSR_LOCAL}. # # Once the database has been "relocated", the client server # software, nsrexecd, is restarted. # # Additionally, we check on the status of any NetWorker GUI programs # running and bring them down gracefully as well. # # #--------------------------------------------------------------------- # Restart syslog # # Only needed in Digital Unix implementations when the /nsr directory # has been moved. #--------------------------------------------------------------------- # restart_syslog() { pid=0 if [ ${ARCH} = DIGITAL ]; then if [ -f /var/run/syslog.pid ]; then pid=`cat /var/run/syslog.pid` fi elif [ ${ARCH} = SOLARIS ]; then if [ -f /etc/syslog.pid ]; then pid=`cat /etc/syslog.pid` fi else pid= fi if [ ! -z "${pid}" ]; then $LOGINFO "Restarting syslog daemon..." kill -1 ${pid} # Give syslog a chance to restart sleep 5 fi } # #--------------------------------------------------------------------- # Find processes # # INPUTS: # process_list= The list of processes names to find # OUTPUTS: # active_processes= The ps output of the processes we targeted. #--------------------------------------------------------------------- # find_processes() { if [ ${ARCH} = SOLARIS ]; then ps_output="`ps -ax | egrep 'nsr|save|nwadmin'`" elif [ ${ARCH} = DIGITAL ]; then ps_output="`ps -eopid,tt,time,comm | egrep 'nsr|save|nwadmin'`" else ps_output="`ps -e | egrep 'nsr|save|nwadmin'`" fi # build up an egrep style pattern we can feed to awk which will match # all the various daemons. pattern= for daemon in $process_list ; do if [ -z "${pattern}" ]; then pattern='[0-9] [-a-zA-Z\+\/._0-9]*('"${daemon}" else pattern="${pattern}|${daemon}" fi done pattern="${pattern}"')' if [ ! -z "${ps_output}" ]; then active_processes="`echo "${ps_output}" | awk '/awk/ { next } $0 ~ /'"$pattern"'/ { print $0 }'`" else active_processes= fi } # Parse program arguments. # parse_args() { while [ $# -gt 0 ] do case $1 in -probe ) ;; -R ) RESOURCE_NAME=$2 shift ;; -T ) RESOURCETYPE_NAME=$2 shift ;; -G ) RESOURCEGROUP_NAME=$2 shift ;; * ) # Just ignore everything else... ;; esac shift done } #--------------------------------------------------------------------------- # Start check execution -- return "1" if NetWorker has been started as cluster # server on this node. #--------------------------------------------------------------------------- NW_CLUSTER_CHECK() { MYLH=$1 answer=0 if [ \( ${CLU_TYPE} = SC22 -a -d /${MYLH} \) -o ${CLU_TYPE} = SC30 ]; then # On Solaris, need to check to see that we haven't already # started nsrd in cluster mode already; do that by looking # at the arguments to possible nsrd processes out there. process_list=nsrd find_processes if [ ! -z "${active_processes}" ]; then # Need to check that the NetWorker deamon is not # running as clustered data service. pattern='nsrd -k '"${MYLH}" pid="`echo "${active_processes}" | awk '/awk/ { next } /'"${pattern}"'/ { print $1 }'`" if [ ! -z "${pid}" ]; then answer=1 fi fi fi return ${answer}; } # #--------------------------------------------------------------------------- # Stop script execution #--------------------------------------------------------------------------- # NW_CLUSTER_STOP() { # # If nsrjb is active, give it some time to complete its operation. # This will minimize the possibility of leaving the jukebox in an # unknown state, though not all jukebox operations will complete in # the time allowed here. # count=`expr 0` process_list=nsrjb while [ $count -lt 24 ] ; do find_processes if [ ! -z "${active_processes}" ]; then sleep 5 else break fi count=`expr $count + 1` done if [ $count -eq 24 ]; then $LOGERR "nsrjb still running at nsr_shutdown time" fi # # Make sure all NetWorker's daemons are killed # process_list=${NSR_DAEMONS} find_processes if [ ! -z "${active_processes}" ]; then $LOGINFO "Killing running ${PRODUCT} daemons on ${HOSTNAME}" ${NSR_STOP} fi # # Recheck. Give the kill command one more minute to finish # retries=12 process_list=${NSR_DAEMONS} while [ ! -z "${active_processes}" ] ; do retries=`expr ${retries} - 1` sleep 5 find_processes done if [ ${retries} -eq 0 ]; then $LOGERR "Unable to kill nsrd; could not stop ${PRODUCT}" $LOGERR "service application ${MYLH} on ${HOSTNAME}" exit 1 fi # # Remove NetWorker GUI if running # process_list=nwadmin find_processes if [ ! -z "${active_processes}" ]; then if [ ${ARCH} = SOLARIS ]; then pid=`echo "${active_processes}" | \ awk '$5 ~ /nwadmin/ { print $1 }'` else pid=`echo "${active_processes}" | \ awk '$4 ~ /nwadmin/ { print $1 }'` fi $LOGINFO "Stopping the ${PRODUCT} GUI" kill -9 ${pid} >/dev/console 2>&1 fi # # Redefine /nsr link to point to local /nsr directory. # rm /nsr ln -s ${NSR_LOCAL} /nsr restart_syslog echo "Stopping ${PRODUCT} service ${MYLH} on ${HOSTNAME}" # # Any non zero exit will be considered a failure. # return 0 } # #--------------------------------------------------------------------- # Main Program: #--------------------------------------------------------------------- # uname=`uname` if [ "X${uname}" = "XSunOS" ]; then ARCH=SOLARIS # Sort out which cluster version pkginfo -q SUNWscmgr if [ $? -eq 0 ]; then # Sun Cluster 2.2 CLU_TYPE=SC22 fi pkginfo -q SUNWscr if [ $? -eq 0 ]; then # Sun Cluster 3.0 CLU_TYPE=SC30 fi pkginfo -q LGTOclnt if [ $? -eq 0 ]; then # EMC NetWorker NSR_STOP="/usr/sbin/nsr_shutdown -fq -t 200" PRODUCT="NetWorker" PRODUCT_TYPE=LGTO fi pkginfo -q SUNWebsc if [ $? -eq 0 ]; then # Sun StorEdge(TM) Enterprise Backup NSR_STOP="/usr/sbin/nsr/nsr_shutdown -fq -t 200" PRODUCT="Sun StorEdge(TM) Enterprise Backup" PRODUCT_TYPE=EBS fi MEMBER_STATE=RUNNING elif [ "X${uname}" = "XOSF1" ]; then ARCH=DIGITAL NSR_STOP="/sbin/init.d/NSRstartstop stop" else $LOGERR "Not an EMC cluster platform. shutting down..." exit 1 fi # NOTE: some systems put "Berkeley" utilities in /usr/ucb, others (e.g. SGI) # put them in /usr/bsd. Also, some systems use /usr/etc and other use # /usr/sbin. We include all variants in addition to the path to this # program to be safe. # mypath="`expr X\"${0}\" : X'\(.*\)/.*' \| X\"${0}\" : X'\(/\)[^/]*$' \| '.'`" PATH=/usr/ucb:/usr/bsd:/bin:/usr/bin:/etc:/usr/etc:/usr/sbin:$mypath:$PATH if [ X${ARCH} = "XDIGITAL" ]; then PATH=$PATH:/usr/opt/networker/bin elif [ ${CLU_TYPE} = SC30 ]; then PATH=$PATH:/usr/cluster/bin fi if [ X${PRODUCT_TYPE} = "XEBS" ]; then PATH=$PATH:/usr/sbin/nsr fi export PATH if [ -f /bin/hostname ]; then HOSTNAME=`/bin/hostname` elif [ -f /usr/ucb/hostname ]; then HOSTNAME=`/usr/ucb/hostname` elif [ -f /usr/bsd/hostname ]; then HOSTNAME=`/usr/bsd/hostname` elif [ -f /usr/local/bin/hostname ]; then HOSTNAME=`/usr/local/bin/hostname` else HOSTNAME= fi if [ X${HOSTNAME} = X ]; then HOSTNAME=`uname -n` fi NSR_LOCAL=/nsr.NetWorker.local NSR_DAEMONS="nsrd nsrexecd nsrmmd nsrmmdbd nsrindexd" BASE=`basename $0` MYLH= if [ ${CLU_TYPE} = SC22 ]; then HAGET=/opt/SUNWcluster/bin/haget LOGERR="logger -t '$HOSTNAME:$BASE'" LOGINFO="logger -t '$HOSTNAME:$BASE'" elif [ ${CLU_TYPE} = SC30 ]; then parse_args $* SYSLOG_FACILITY=`scha_cluster_get -O SYSLOG_FACILITY` LOGERR="logger -t '$HOSTNAME:$BASE' -p ${SYSLOG_FACILITY}.err" LOGINFO="logger -t '$HOSTNAME:$BASE' -p ${SYSLOG_FACILITY}.info" MYLH=`scha_resource_get -G ${RESOURCEGROUP_NAME} -R ${RESOURCE_NAME} -O EXTENSION Servername | tail +2` if [ -z "${MYLH}" ] ; then MYLH=`scha_resource_get -G ${RESOURCEGROUP_NAME} -R ${RESOURCE_NAME} -O NETWORK_RESOURCES_USED` fi NSR_SHARED_DISK_DIR=`scha_resource_get -G ${RESOURCEGROUP_NAME} -R ${RESOURCE_NAME} -O EXTENSION Config_dir |tail +2` fi if [ ${CLU_TYPE} = SC22 ]; then # Replace comma with space to form an sh word list: NOT_MASTERED_LOGICAL_HOSTS="`echo $2 | tr ',' ' '`" if [ -z "${NOT_MASTERED_LOGICAL_HOSTS}" ]; then # This physical host currently masters all logical hosts exit 0 fi # # Dynamically search the list of logical hosts which this physical # host currently masters, to see if one of them is the logical host # that NetWorker uses # for LH in ${NOT_MASTERED_LOGICAL_HOSTS} ; do # Check to see if any of the non-mastered logical hosts # are being run on this host by NetWorker NW_CLUSTER_CHECK ${LH} if [ $? -eq 1 ]; then MYLH=${LH} break fi done elif [ ${CLU_TYPE} = SC30 ]; then # MYLH was already set when running networker.cluster. continue elif [ ! -z "$1" ]; then # This physical host does not currently master any logical hosts. MYLH=$1 fi if [ -z "${MYLH}" ]; then # Didn't find the database file which indicates which logical # host to shut down. Now, use the NOT_MASTERED list to figure # if we are running nsrd for a logical host that we are not # the master for. If so, ...shut it down. MEMBER_STATE=NOT_RUNNING fi # # This script runs when the service is stopped, and also (on Digital # Unix) when the ASE is initializing on a member as it boots. You # can test the context: # case "${MEMBER_STATE}" in BOOTING) # Stopping ${MYLH} as cluster member boots. NW_CLUSTER_STOP ${MYLH} RC=$? ;; RUNNING) # This is a true stop of ${MYLH}. NW_CLUSTER_STOP ${MYLH} RC=$? ;; NOT_RUNNING) RC=0 ;; esac if [ ${RC} -eq 0 ]; then # Good state. Make sure that the nsrexecd daemon is running. process_list=nsrexecd find_processes if [ -z "${active_processes}" ]; then nsrexecd cat < /nsr/tmp/nsradminfile #!/bin/sh sleep 60 nsradmin -p nsrexecd <