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

NAME=juman
DAEMON="/usr/bin/$NAME"
DESC="Juman server"

test -f $DAEMON || exit 0

PARAMS="-S"

check_for_no_start() {
    if [ ! -e /etc/juman_server_to_be_run ]; then 
	echo "Juman server not in use (/etc/juman_server_to_be_run)"
	exit 0
    fi
}

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

exit 0
