#!/bin/sh
#
# zhm:	Start the Zephyr Host Manager
#
# chkconfig: 2345 80 30
# description: Zhm startup.
# processname: zhm
#
# config: /etc/sysconfig/network

# Source function library
. /etc/rc.d/init.d/functions

. /etc/sysconfig/network

PATH=/bin:/usr/bin:/usr/sbin:$PATH

# Check that networking is up.
if [ ${NETWORKING} = "no" ]
then
	exit 0
fi

[ -f /usr/sbin/zhm ] || exit 0


RETVAL=0

start () {
	echo -n "Starting MIT zephyr host manager: "
	HESTEST=`/usr/bin/hesinfo zephyr sloc 2>/dev/null`

	if [ -z "$HESTEST" ]; then
	    echo "Cannot lookup servers.  No network?"
	    echo_failure
	    echo
	    exit 1
	else
	    daemon zhm
	    RETVAL=$?
	fi

	echo
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/zhm
	return $RETVAL
}

stop () {
	echo -n "Stopping MIT zephyr host manager: "
	killproc zhm
	RETVAL=$?

	echo
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/zhm
}

restart() {
    stop
    start
}


# See how we were called
case "$1" in
  start)
	start
	;;

  stop)
	stop
	;;

  status)
	status zhm
	RETVAL=$?
	;;

  restart)
	restart
	;;

  condrestart)
	[ -f /var/lock/subsys/zhm ] && restart || start
	;;

  reload)
	killall -HUP zhm
	RETVAL=$?
	;;

  *)
	echo "Usage: zhm {start|stop|status|restart|reload}"
	exit 1
esac

exit $RETVAL
