#! /bin/sh
#
# /etc/init.d/noflushd: Control userland daemon to spin down idle disks
#

NAME=noflushd
DAEMON="/usr/sbin/$NAME"
DESC="No Flush Daemon"
DEFAULTS=/etc/default/noflushd

test -f $DAEMON || exit 0

# Source defaults file; edit that file to configure this script.
TIMEOUT=0
DISKS=""
PARAMS=""
if [ -e "$DEFAULTS" ]; then
	. "$DEFAULTS"
fi
if [ -z "$PARAMS" ]; then
	if [ -z "$DISKS" ]; then
		printf "You need to edit $DEFAULTS before using $NAME.\n"
		exit 0
	fi
	PARAMS="-n $TIMEOUT $DISKS"
fi

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON -- $PARAMS
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON -- $PARAMS 
	echo "$NAME."
	;;
  restart|force-reload)
	echo -n "Restarting $DESC: "
	start-stop-daemon --stop --quiet --pidfile \
		/var/run/$NAME.pid --exec $DAEMON -- $PARAMS
	sleep 1
	start-stop-daemon --start --quiet --pidfile \
		/var/run/$NAME.pid --exec $DAEMON -- $PARAMS
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
