#!/bin/sh

#
# zmailer 	This shell script takes care of starting and stopping
#		zmailer
#
# chkconfig: 2345 80 30
# description: zmailer is a MTA, 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

if [ -z "$ZCONFIG" ] ; then
    ZCONFIG=/etc/mail/zmailer.conf
fi

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|restart}"
	exit 0
	;;
esac
exit 0
