#!/bin/sh
#
# chkconfig: - 91 35
# description: Starts and stops the Uhub ( http://www.uhub.org ) daemons on RHEL\CentOS \
#	       used to provide p2p network services.
#
# pidfile: /var/run/uhub.pid
# config:  /etc/uhub/uhub.conf



# Source function library.
if [ -f /etc/init.d/functions ] ; then
  . /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
  . /etc/rc.d/init.d/functions
else
  exit 1
fi

# Avoid using root's TMPDIR
unset TMPDIR

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

if [ -f /etc/sysconfig/uhub ]; then
   . /etc/sysconfig/uhub
fi

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

# Check that bin and uhub.conf exists.
[ -f $UHUBBINFILE ] || exit 6
[ -f /etc/uhub/uhub.conf ] || exit 6

RETVAL=0


start() {
        KIND="Uhub"
	echo -n $"Starting $KIND services: "
	daemon $UHUBBINFILE $UHUBOPTIONS
	RETVAL=$?
        echo "" 
	return $RETVAL
}	

stop() {
        KIND="Uhub"
	echo -n $"Shutting down $KIND services: "
	killproc  $UHUBBINFILE
	RETVAL=$?
	echo ""
	return $RETVAL
}	

restart() {
	stop
	start
}	

reload() {
        echo -n $"Reloading uhub.conf / user.conf file: "
	killproc uhub -HUP
	RETVAL=$?
	echo ""
	return $RETVAL
}	

relog() {
    echo -n $"Reopen main log file: "
     killproc uhub -SIGHUP
     RETVAL=$?
     echo ""
     return $RETVAL
}

rhstatus() {
	status  $UHUBBINFILE
        RETVAL=$?
        if [ $RETVAL -ne 0 ] ; then
                return $RETVAL
        fi
}


case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  reload)
  	reload
	;;
  relog)
	relog
	;;
  status)
  	rhstatus
	;;
  *)
	echo $"Usage: $0 {start|stop|restart|reload|relog|status}"
	exit 2
esac

exit $?
