#! /bin/sh
### BEGIN INIT INFO
# Short-Description: Courier WebMLM server
# Provides:          courier-mlm
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
### END INIT INFO
#
# Copyright 2007,2008 by Stefan Hornburg (Racke) <racke@linuxia.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA  02111-1307  USA.

PROGRAM=webmlmd
DAEMON=/usr/bin/$PROGRAM
CONFIGFILE=/etc/courier/webmlmrc
NAME="WebMLM daemon"

# load LSB functions
set -e
. /lib/lsb/init-functions

# stop if the sqwebmail package has been removed
if ! [ -x $DAEMON ]; then
	exit 0
fi

test_config() {
    set +e
	. $CONFIGFILE
	if [ -z "$LISTS" ]; then
		log_begin_msg "$NAME: lists directories missing from configuration file, not starting/reloading..."
		log_end_msg 1
		return 1
	fi
	set -e
}

case "$1" in
start)
    if ! test_config; then
		exit 0
	fi

	# Start webmlm daemon
    log_begin_msg "Starting $NAME" $PROGRAM
	if $DAEMON start $CONFIGFILE; then
		log_end_msg 0
	else
		log_end_msg 1
	fi
	;;
stop)
	# Stop webmlm daemon
    log_begin_msg "Stopping $NAME" $PROGRAM
	if $DAEMON stop $CONFIGFILE; then
		log_end_msg 0
	else
		log_end_msg 1
	fi
	;;
restart | force-reload)
    $0 stop
    $0 start
    ;;
*)
	log_success_msg "Usage: $0 {start|stop|restart|force-reload}"
	exit 2
	;;
esac

exit 0

