#! /bin/sh

case "$1" in

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

set -e

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

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

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

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