#!/bin/sh
#
# $NetBSD: webmlm.sh,v 1.4 2008/02/19 18:45:24 jlam Exp $
#
# Courier mailing list management daemon
#
# PROVIDE: webmlm
# REQUIRE: DAEMON
# KEYWORD: shutdown

. /etc/rc.subr

name="webmlm"
rcvar=${name}
command="/usr/pkg/sbin/courierlogger"
ctl_command="/usr/pkg/bin/webmlmd.rc"
pidfile="/var/courier/webmlm.pid"
required_files="/usr/pkg/etc/courier/webmlmrc"

restart_cmd="${name}_doit restart"
start_precmd="${name}_prestart"
start_cmd="${name}_doit start"
stop_cmd="${name}_doit stop"

webmlm_prestart()
{
	test -d /var/courier || /bin/mkdir -p /var/courier
}

webmlm_doit()
{
	action=$1

	. /usr/pkg/etc/courier/webmlmrc
	test -n "$LISTS" || return 0

	case $action in
        restart|start)
		for f in $required_files; do
			if [ ! -r "$f" ]; then
				echo 1>&2 "$0: WARNING: $f is not readable"
				return 1
			fi
		done
		case $action in
		restart)	echo "Restarting ${name}." ;;
		start)		echo "Starting ${name}." ;;
		esac
		;;
	stop)
		echo "Stopping ${name}."
		;;
	esac

	${ctl_command} /usr/pkg/bin/webmlmd $action \
		/usr/pkg/etc/courier/webmlmrc
}

load_rc_config $name
run_rc_command "$1"
