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

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

# Get network config
. /etc/sysconfig/network

# Get service config
SourceIfNotEmpty /etc/sysconfig/whoson

PIDFILE=/var/run/whosond.pid
LOCKFILE=/var/lock/subsys/whosond
RETVAL=0

start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user nobody whosond
	RETVAL=$?
        return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user nobody whosond
	RETVAL=$?
	return $RETVAL
}

reload()
{
	msg_reloading whosond
	stop_daemon --pidfile "$PIDFILE" --expect-user nobody -HUP whosond
	RETVAL=$?
	return $RETVAL
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  restart)
	stop
	start
	;;
  reload)
	reload
	;;
  condstop)
	if [ -e "$LOCKFILE" ]; then
		stop
	fi
	;;
  condrestart)
	if [ -e "$LOCKFILE" ]; then
		restart
	fi
	;;
  condreload)
	if [ -e "$LOCKFILE" ]; then
		reload
	fi
	;;
  status)
	status --pidfile "$PIDFILE" --expect-user nobody whosond
	RETVAL=$?
        ;;
  *)
	msg_usage "Usage: ${0##*/} {start|stop|status|reload|restart|condstop|condrestart|condreload}"
        RETVAL=1
esac

exit $RETVAL
