#!/bin/sh
#
# Copyright 1999 Sun Microsystems, Inc. All Rights Reserved
#
# @(#)ss_ha_restart.sh	3.5 03/11/99 Sun Microsystems, Inc.
#
# usage: ss_ha_restart [-f]
#

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

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

start_daemon()
{
    pidfile=${SS_VARDIR}/$1.pid
    /bin/sh -c 'echo $$'" >$pidfile; exec ${SS_LIBDIR}/$* >/dev/console 2>&1" &
}

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

FORCE=false

if [ "$1" = "-f" ]
then
	FORCE=true
	shift
fi

#
# restart local daemon
#
if $FORCE
then
	#
	# force restart of HA daemon
	#
	if [ -n "$pid" ]
	then	echo "Killing old HA daemon"
		kill $pid >/dev/null 2>&1
		sleep 5
		kill -KILL $pid >/dev/null 2>&1
	fi
	echo "Starting: $HA_PROGNAME"
	start_daemon ss_had
else
	if [ -n "$pid" ]
	then	echo "Re-initializing $HA_PROGNAME"
		kill -HUP $pid >/dev/null 2>&1
	else
		echo "Starting: $HA_PROGNAME"
		start_daemon ss_had
	fi
fi

# We don't need to call ss_ha_sync_config to push over the configuration
# because "ssadm activate" alread does that.
#
# syncronize configurations with other HA hosts 
#
#exec ss_ha_sync_config
