#! /bin/sh

case "$0" in

/*)
	prog="$0"
	;;
*)
	prog="`which $0`"
	;;
esac

set -e

case "$1" in
start)
	if test "$2" = ""
	then
		echo "Usage: $prog start [configfile]" >&2
		exit 1
	fi

	/usr/bin/env -i /bin/sh -c "set -a; . $2; $prog check || exit 1; \
		/usr/local/sbin/courierlogger -pid="'"${PIDFILE}"'" $LOGGEROPTS -start $prog"
	exit $?
	;;
stop)
	if test "$2" = ""
	then
		echo "Usage: $prog stop [configfile]" >&2
		exit 1
	fi

	/usr/bin/env -i /bin/sh -c "set -a; . $2;\
		/usr/local/sbin/courierlogger -pid="'"${PIDFILE}"'" $LOGGEROPTS -stop $prog"
	exit $?
	;;
restart)
	if test "$2" = ""
	then
		echo "Usage: $prog restart [configfile]" >&2
		exit 1
	fi

	/usr/bin/env -i /bin/sh -c "set -a; . $2; $prog check || exit 1; \
		/usr/local/sbin/courierlogger -pid="'"${PIDFILE}"'" $LOGGEROPTS -restart $prog"
	exit $?
	;;
*)
	echo "Invalid command" >&2
	exit 1
esac
