#!/bin/sh
#
# stunserver		This shell script takes care of starting and stopping stunserver.
#
# chkconfig:	2345 80 30
# description:	stunserver is a STUN protocol server
#
# processname:	stunserver

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

# Source networking configuration.
. /etc/sysconfig/network

# Source oident configureation.
if [ -f /etc/sysconfig/stunserver ]; then
	. /etc/sysconfig/stunserver
fi

# Check that networking is up.
if is_yes "${NETWORKING}"; then
	if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status ]; then
		msg_network_down stunserver
		exit 1
	fi
else
	exit 0
fi

start() {
	# Start daemons.
	if [ ! -f /var/lock/subsys/stunserver ]; then
		msg_starting stunserver
		daemon --user nobody --fork /usr/bin/stunserver $STUNSERVER_OPTIONS
		RETVAL=$?
		[ $RETVAL -eq 0 ] && touch /var/lock/subsys/stunserver
	else
		msg_already_running stunserver
	fi
}

stop() {
	# Stop daemons.
	if [ -f /var/lock/subsys/stunserver ]; then
		msg_stopping stunserver
		killproc stunserver
		rm -f /var/lock/subsys/stunserver >/dev/null 2>&1
	else
		msg_not_running stunserver
	fi
}

condrestart() {
	if [ -f /var/lock/subsys/stunserver ]; then
		stop
		start
	else
		msg_not_running stunserver
		RETVAL=$1
	fi
}

RETVAL=0
# See how we were called.
case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
	stop
	start
	;;
  try-restart)
	condrestart 0
	;;
  force-reload)
	condrestart 7
	;;
  status)
	status stunserver
	exit $?
	;;
  *)
	msg_usage "$0 {start|stop|restart|try-restart|force-reload|status}"
	exit 3
esac

exit $RETVAL
