#!/bin/sh
#
# zmailer       This shell script takes care of starting and stopping
#               zmailer.
#
# chkconfig: 2345 80 30
# description: zmailer is a Mail Transport Agent, which is the program \
# that moves mail from one machine to another.

export PATH=/bin:/sbin:/usr/bin:/usr/sbin

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "${NETWORKING}" == "no" ] && exit 0

ZCONFIG=/etc/mail/zmailer.conf

[ -f $ZCONFIG ] || exit 0

if [ -r $ZCONFIG ]; then
	. $ZCONFIG
else
	exit 0
fi

case "$1" in
start)
	if [ "${SMTPSERVER}" ]; then
		show Starting ZMailer smtp daemon; busy
		if $$MAILBIN/zmailer smtp > /dev/null 2>&1 ; then
			deltext; ok
		else
			deltext; fail
		fi
		
	elif [ ${MAILSERVER-NONE} = NONE -a -x $MAILBIN/zmailer ]; then
		show Starting ZMailer bootcleaning; busy
                if $MAILBIN/zmailer bootclean > /dev/null 2>&1 ; then
                        deltext; ok
                else
                        deltext; fail
                fi

		show Starting Zmailer main daemon; busy
                if $MAILBIN/zmailer > /dev/null 2>&1 ; then
                        deltext; ok
                else
                        deltext; fail
                fi
	fi
	touch /var/lock/subsys/zmailer
	;;

stop)
	if [ ${MAILSERVER-NONE} = NONE -a -x $MAILBIN/zmailer ]; then
		show Stopping ZMailer daemons; busy
                if $MAILBIN/zmailer kill > /dev/null 2>&1 ; then
                        deltext; ok
                else
                        deltext; fail
                fi

	fi
	rm -f /var/lock/subsys/zmailer
	;;
restart)
	$0 stop
	$0 start
	;;
*)
	echo "Usage: $0 {start|stop}"
	exit 0
	;;
esac
exit 0
