#! /bin/sh
#
# /etc/init.d/freeb
# Jeff Buchbinder <jeff@freemedsoftware.com>
# GPL

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
NAME=freeb
DAEMON=/usr/share/${NAME}/bin/FreeB_Server.pl
DESC="FreeB Billing Service"

test -x $DAEMON || exit 0

# Include freeb defaults if available
if [ -f /etc/default/${NAME} ] ; then
	. /etc/default/${NAME}
fi

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
		--make-pidfile --background --exec $DAEMON -- $DAEMON_OPTS
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	# Hacky as hell.. start-stop-daemon doesn't work here
	kill -9 `cat /var/run/$NAME.pid` 2>&1 > /dev/null
	#start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
	#	--exec $DAEMON
	echo "$NAME."
	;;
  restart|force-reload)
        sh $0 stop
	sleep 1
	sh $0 start
	;;
  *)
	echo "Usage: $0 {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
