#!/bin/bash
#
# re6stnet  Resilient, Scalable, IPv6 Network application
#
# chkconfig: 2345 08 92
# description: Start, stops and restart re6stnet
#
# config: /etc/re6stnet/re6stnet.cfg
#
### BEGIN INT INFO
# Provides: re6stnet
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start, stops and restart re6stnet
# Description: Start, stops and restart re6stnet
### END INIT INFO


# PATH should only include /usr/* if it runs after the mountnfs.sh script
PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/bin
NAME=re6stnet
DESC="Resilient, Scalable, IPv6 Network application"
DAEMON=/usr/sbin/$NAME
CONFDIR=/etc/re6stnet
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME

LOCKFILE=/var/lock/subsys/re6stnet

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

start() {
        echo -n "Starting $NAME: "
        /usr/local/bin/daemon --user root -n $NAME --pidfile=$PIDFILE -D $CONFDIR -- $DAEMON @re6stnet.conf 
        RETVAL=$?
        [ $RETVAL -eq 0 ] && touch $LOCKFILE
        [ $RETVAL -eq 0 ] && echo OK || echo FAIL
        echo
        return $RETVAL
}

stop() {
        echo -n "Shutting down $NAME: "
        /usr/local/bin/daemon --user root -n $NAME --pidfile=$PIDFILE --stop
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -rf $LOCKFILE
        [ $RETVAL -eq 0 ] && echo OK || echo FAIL
        echo
        return $RETVAL
}

status() {
        echo -n "Status for $NAME: "
        /usr/local/bin/daemon --user root -n $NAME --pidfile=$PIDFILE --running                               
        RETVAL=$?
        [ $RETVAL -eq 0 ] && echo OK || echo FAIL
        echo
        return $RETVAL
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status
        ;;
    restart)
        stop
        start 
        ;;
    *)
        echo "Usage: <servicename> {start|stop|status|restart}"
        exit 1
        ;;
esac
exit $?
