#!/bin/sh
#
# udpxy		This shell script takes care of starting and stopping
#		udpxy (multicast traffic relay daemon).
#
# chkconfig: - 58 10
# description: udpxy is the multicast traffic relay daemon.

### BEGIN INIT INFO
# Provides:          ntp
# Required-Start:    $network $remote_fs $syslog
# Required-Stop:     $network $remote_fs $syslog
# Default-Start:     
# Default-Stop:      0 1 2 3 4 5 6
# Short-Description: Start udpxy daemon
# Description:       Enable udpxy daemon.
### END INIT INFO

WITHOUT_RC_COMPAT=1

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

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

# Source service configuration.
SourceIfNotEmpty /etc/sysconfig/udpxy

PIDFILE=/var/run/udpxy.pid
LOCKFILE=/var/lock/subsys/udpxy
RETVAL=0
# TODO:
UDPXY_USER=nobody

start()
{
	is_yes "$NETWORKING" || return 0
	# TODO: --user "$UDPXY_USER"
	start_daemon --name udpxy --make-pidfile --pidfile "$PIDFILE" --background -- udpxy -T $OPTIONS
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --name udpxy --pidfile "$PIDFILE" -- udpxy
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

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

exit $RETVAL
