#!/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=rpc.rquotad
DESC="quota service"

# names of binaries
DAEMON=/usr/sbin/rpc.rquotad

# check if quota are enabled
if grep -q '^[^#]*quota' /etc/fstab && grep -q '^/' /etc/exports; then
        need_rquotad=1
else
        need_rquotad=0
fi

test -f $DAEMON || exit 0

set -e

case "$1" in
  start)
	# The daemon
	if [ -x $DAEMON -a $need_rquotad = 1 ]; then
	   echo -n "Starting $DESC: "
	   if start-stop-daemon --start --quiet --exec $DAEMON
	   then
		echo "rpc.rquotad."
	   else
		echo "."
	   fi
	fi	
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
	echo "$NAME."
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	$0 stop
	$0 start
	;;
  *)
	echo "Usage: $0 {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
