#!/bin/bash
#
# stund      This shell script takes care of starting and stopping
#            standalone stund.
#
# chkconfig: 345 60 50
# description: stund is a STUN daemon 
# processname: stund
# config: /etc/sysconfig/stund

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

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

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

[ -x /usr/sbin/stund ] || exit 0

# Source stund configuration.
. /etc/sysconfig/stund
[ -n "$PRIMARY_IP" ] || exit 0
[ -n "$SECONDARY_IP" ] || exit 0

RETVAL=0
prog="stund"

start() {
        su - stund -c /usr/sbin/stund -h $PRIMARY_IP -a $SECONDARY_IP -p $PRIMARY_PORT -o $SECONDARY_PORT -b
        touch /var/lock/subsys/stund
        return $RETVAL
}

stop() {
        # Stop daemons.
        echo -n $"Shutting down $prog: "
        killproc $prog
        RETVAL=$?
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog
        return $RETVAL
}

# See how we were called.
case "$1" in
  start)
        start
        ;;
  stop)
        stop
        ;;
  restart|reload)
        stop
        start
        RETVAL=$?
        ;;
  condrestart)
        if [ -f /var/lock/subsys/$prog ]; then
            stop
            start
            RETVAL=$?
        fi
        ;;
  status)
        status $prog
        RETVAL=$?
        ;;
  *)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        exit 1
esac

exit $RETVAL
