#!/bin/bash
#
# whosond	Start/Stop whosond server
#
# chkconfig:	345 40 65
# description:	whosond - implementation of WHOSON protocol
#
# processname:	whosond
# config:	/etc/whoson.conf

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

# Get network config
. /etc/sysconfig/network

# Get service config
[ -f /etc/sysconfig/whoson ] && . /etc/sysconfig/whoson

# Check that networking is up.
if [ "${NETWORKING}" = "no" ]; then
	echo "WARNING: Networking is down. Whoson service can't be run."
	exit 1
fi

# See how we were called.
case "$1" in
  start)
	# Check if the service is already running?
	if [ ! -f /var/lock/subsys/whosond ]; then
		msg_starting "whosond"
		daemon whosond
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/whosond
	else
		msg_Already_Running whosond
		exit 1
	fi
        ;;
  stop)
        # Stop daemons.
	if [ -f /var/lock/subsys/whosond ]; then
		msg_stopping whosond
		killproc whosond
		rm -f /var/lock/subsys/whosond >/dev/null 2>&1
	else
		msg_Not_Running whosond
		exit 1
	fi	
        ;;
  restart)
        $0 stop
	$0 start
        ;;
  reload)
	if [ -f /var/lock/subsys/whosond ]; then
		msg_show whosond
		msg_reload
		busy
		killproc whosond -HUP
		deltext
		ok		
	else
		msg_Not_Running whosond
		exit 1
	fi
	;;
  force-reload)
	$0 stop && $0 start
	exit $?
	;;
  status)
	status whosond
	exit $?
        ;;
  *)
        # show "Usage: %s {start|stop|status|restart|reload|force-reload}" $0
	msg_Usage "$0 {start|stop|status|restart|reload|force-reload}"
        exit 1
esac

exit $RETVAL
