#!/bin/ksh
#
#pragma ident   "@(#)netreconfig.sh	1.2	98/08/26"
#Copyright (C) 1997 Sun Microsystems, Inc.
#
#
 
# netreconfig - SunCluster Public Network Monitory Framework component
#
# Input:
#               All environment variables like "currnodes"/
#               "allnodes"/"localnodeid", CURRSTEP
#
# Action:       Run Reconfiguration Programs based on current
#               "cmmstepN"|"cmmabort"|"cmmstart"|"cmmreturn".
#
# Output:       Return 0 if success.
#               Return 1 if failure
#               Return 200 if reconfigurtion program result is to
#               be ignored.
 
# should be used only the reconf_framework.
pre="SUNWcluster.reconf.netmon"
 
RECONF_SCRIPTS=${RECONF_SCRIPTS:-/opt/SUNWcluster/etc/reconf/scripts}
CLUSTERBIN=${CLUSTERBIN:-/opt/SUNWcluster/bin/}
CLUSTERVAR=${CLUSTERVAR:-/var/opt/SUNWcluster/}
CLUSTERETC=${CLUSTERETC:-/etc/opt/SUNWcluster/}

##########################################################################
#
# function netmon_error
#
# Prints an error message on the console based on the value of the first
# argument.
#
# $1 = 1, nametag already exists
# $1 = 2, command timed out
# $1 > 2, internal error occurred
#

function netmon_error
{
typeset error
error=$1

case ${error} in
  0) ;;
  1) log_info "${pre}.5000" "PMF: nametag netfmd already exists" ;;
  2) log_info "${pre}.5001" "PMF: netfmd command timed out" ;;
  *) log_info "${pre}.5002" "PMF: Internal error occurred" ;;
esac
}


##########################################################################
#
# function netmonstep1_cmd
#
# Uses the pmfadm facility to start and stop the actual process doing the
# network monitoring.

function netmonstep1_cmd
{
# If we are starting and netfmd is already running, kill it and
# then restart.
	if ${CLUSTERBIN}/pmfadm -l netfmd > /dev/null 2>&1; then
		${CLUSTERBIN}/pmfadm -s netfmd KILL
		sleep 1
	fi

# We are going to start this so that it runs indefinately.
	${CLUSTERBIN}/pmfadm -c netfmd -n -1 -t 5 -a /bin/true \
		${CLUSTERBIN}/netmon || netmon_error $?

}

###########################################################################
#
# function netmonstop_cmd
#
# Uses the pmfadm facility to stop the process doing the public network
# monitoring.
#

function netmonstop_cmd
{
if ${CLUSTERBIN}/pmfadm -l netfmd > /dev/null 2>&1; then
  ${CLUSTERBIN}/pmfadm -s netfmd KILL
fi
}


case ${CURRSTEP} in
  cmmabort | stopnode | cmmreturn)
	  netmonstop_cmd ;;
  cmmstep12 )
	  netmonstep1_cmd ;;
  *) ;;
esac

exit 0
