#!/bin/bash
#
#       /etc/rc.d/init.d/xbt-tracker
#
#       XBT Tracker is a BitTorrent tracker
#
# <tags -- see below for tag definitions.  *Every line* from the top
#  of the file to the end of the tags section must begin with a #
#  character.  After the tags section, there should be a blank line.
#  This keeps normal comments in the rest of the file from being
#  mistaken for tags, should they happen to fit the pattern.>

# xbt-tracker Starts/stop the "xbt-tracker" daemon
#
# chkconfig:   345 95 5
# description: Runs xbt-tracker 
#
# Source function library.
. /etc/init.d/functions

XBT_TRACKER="/usr/sbin/xbt-tracker"
XBT_CONF="/etc/xbt-tracker/xbt-tracker.conf"

start() {
        echo -n "Starting xbt-tracker: "
	$XBT_TRACKER --conf_file $XBT_CONF
	retval=$?
	echo
	[ $retval -eq 0 ] && touch /var/lock/subsys/xbt-tracker
        return $retval
}

stop() {
        echo -n "Shutting down xbt-tracker: "
	if [ -n "`pidfileofproc $XBT_TRACKER`" ] ; then
		killproc $XBT_TRACKER
			RETVAL=3
	else
        	failure $"Stopping xbt-tracker"
	fi
	retval=$?
	echo
	[ $retval -eq 0 ] && rm -f /var/lock/subsys/xbt-tracker
        return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

rh_status() {
    status $XBT_TRACKER
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
	rh_status_q && exit 0
        $1
        ;;
    stop)
	rh_status_q || exit 0
        $1
        ;;
    status)
	rh_status
        ;;
    restart)
	$1
        ;;
    reload)
	rh_status_q || exit 7
	$1
        ;;
    condrestart)
	rh_status_q || exit 0
	restart
	;;
    *)
        echo "Usage: <servicename> {start|stop|status|reload|restart}"
        exit 1
        ;;
esac
exit $?
