#!/bin/sh
#
# Copyright 1996-1999 Sun Microsystems, Inc. All Rights Reserved
#
# ident "@(#)ss_ha_active_mode.sh	3.3 11/18/99 Sun Microsystems"
#
# usage: ss_ha_active_mode [-Z]
#

HA_PROGNAME="ss_had"
SS_VARDIR=/var/opt/SUNWicg/SunScreen
HA_PIDFILE=${SS_VARDIR}/ss_had.pid
SS_LIBDIR=/opt/SUNWicg/SunScreen/lib
KILL=/bin/kill

PATH="/opt/SUNWicg/SunScreen/bin:/usr/bin"
export PATH

###
### NOTE: Use this command with caution.  Enabling the sending of packets on 
###       a HA host that is currently a passive HA host while another
###       host is still in active mode can result in strange network
###	  behavior: confused ARP caches, confused routing, and lost
###       connections.
###

if [ "$1" != "-Z" ] ; then
  echo ""
  echo "WARNING: You are about to put this machine in active mode."
  echo " This will enable the sending of packets from this machine"
  echo " even if the machine is currently in passive mode.  Doing so"
  echo " may disrupt traffic that is going into or through this"
  echo " HA cluster if high availability (HA) is configured.  This"
  echo " command should only be used in conjunction with the HA"
  echo " feature."
  echo ""
  echo "Do you want to put this SunScreen in active mode ? (Y/N)"
  read ANSWER
  case $ANSWER in
    Y|y|Yes|YES|yes)
		     # continue
		     ;;
    *)
                     # all other responses are considered a "no"
                     echo "No action taken."
                     exit 0
		     ;;
  esac
fi

if [ -f $HA_PIDFILE ] && read pid <$HA_PIDFILE &&
   /usr/bin/ps -fp$pid | /usr/bin/fgrep $HA_PROGNAME >/dev/null
then :
else /bin/rm -f $HA_PIDFILE
     pid=
fi

#
# If ss_had is running, we signal it such that it can perform necessary
# actions to make this screen active. Otherwise, we just do it ourselves.
#
#
if [ -n "$pid" ]
then $KILL -USR1 $pid
else exec $SS_LIBDIR/ss_disable_send ENABLE
fi
