#!/bin/bash
#
# udpxy: Starts the udpxy daemon
#
# chkconfig:   345 90 25
# description: This is a daemon which forwards UDP traffic \
#              from a given multicast subscription \
#              to the requesting HTTP client.
# processname: udpxy
# pidfile: /var/run/udpxy.pid
# config: /etc/sysconfig/udpxy

# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: udpxy
# Required-Start: $network $local_fs
# Required-Stop: $network $local_fs
# Should-Start: $syslog
# Should-Stop: $syslog
# Default-Start: 3 4 5
# Default-Stop: 0 1 2 6
# Short-Description: start and stop udpxy daemon
# Description: UDP-to-HTTP multicast traffic relay daemon
### END INIT INFO

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

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

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

[ -f /etc/sysconfig/udpxy ] || exit 0

. /etc/sysconfig/udpxy

RETVAL=0

# See how we were called.
case "$1" in
  start)
    if [ -n "`/sbin/pidof udpxy`" ]; then
        action "Starting udpxy fail (already running): " /bin/false
        exit 1
    fi
    gprintf "Starting udpxy daemon"
    daemon udpxy $OPTIONS
    sleep 1
    if [ -n "`/sbin/pidof udpxy`" ]; then
	success
    fi
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/udpxy
    ;;
  stop)
    gprintf "Shutting down udpxy daemon: "
    killproc udpxy
    RETVAL=$?
    echo
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/udpxy
    ;;
  status)
    status udpxy
    RETVAL=$?
    ;;
  restart|reload)
    $0 stop
    $0 start
    RETVAL=$?
    ;;
  condrestart)
    if [ -f /var/lock/subsys/udpxy ]; then
        $0 stop
        $0 start
    fi
    ;;
  *)
    gprintf "Usage: udpxy {start|stop|status|restart|reload|condrestart}\n"
    exit 1
esac

exit $RETVAL
