#!/bin/bash
#
#       /etc/rc.d/init.d/xrd
#
# Starts xrootd 
#
# chkconfig: 345 95 5
# description: Starts xrootd 
# processname: xrootd

# Source function library.
XRDLOCATION="/usr/local/xrootd"

if test ! -x ${XRDLOCATION}/bin/xrootd ; then
  echo Error: ${XRDLOCATION}/bin/xrootd does not exist
  exit 0
fi
 

if test ! -x ${XRDLOCATION}/scripts/xrootd/xrd.sh ; then
  echo Error: {XRDLOCATION}/scripts/xrootd/xrd.sh does not exist
  exit 0
fi
 
start() {
        echo -n "Starting xrootd services: "
        ${XRDLOCATION}/scripts/xrootd/xrd.sh -c
        return $?
}

stop() {
        echo -n "Stopping xrootd services: "
        ${XRDLOCATION}/scripts/xrootd/xrd.sh -k
        RETVAL=$?
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/xrootd
        echo
        return $RETVAL
}


restart() {
        stop
        start
}       

reload() {
        restart
}       


case "$1" in
start)
        start
        ;;
stop)
        stop
        ;;
reload|restart)
        restart
        ;;
condrestart)
        if [ -f /var/lock/subsys/xrootd ]; then
            restart
        fi
        ;;
status)
        ;;
*)
        echo $"Usage: $0 {start|stop|restart|condrestart|status}"
        exit 1
esac

exit $?
exit $RETVAL
