#!/bin/sh

# mysqmail-postfix-logger            Logs postfix traffic to MySQL
# 
# chkconfig: 345 99 00
# description: mysqmail-postfix-logger logs all the traffic of your MTA
# 	to a MySQL database in order to keep monthly score boards in DTC.
# processname: mysqmail-postfix-logger
# pidfile: /var/run/mysqmail-postfix-logger.pid
# config: /etc/mysqmail.conf
#
# Based on Postfix startup script distributed in Fedora

. /etc/rc.d/init.d/functions

PATH=$PATH:/bin:/usr/bin:/usr/sbin
DESC="MySQMail postfix logger"
NAME=mysqmail-postfix-logger
DAEMON=/usr/sbin/${NAME}
PID_FILE=/var/run/${NAME}.pid

if [ ! -x ${DAEMON} ] ; then
	echo "${DAEMON} not executable or not present!"
	exit 1
fi
if [ ! -f /etc/mysqmail.conf ] ; then
	echo "Config file /etc/mysqmail.conf not found: exiting"
	exit 1
fi

status -p $PID_FILE ${NAME} >/dev/null 2>&1
running=$?

start() {
	# Start daemons.
	echo -n $"Starting ${DESC}: "
	daemon ${DAEMON}
	RETVAL=$?
	echo ""
	return $RETVAL
}

stop() {
        # Stop daemons.
	echo -n $"Stopping ${DESC}: "
	killproc -p $${PID_FILE} ${NAME} && success || failure $"$prog stop"
	RETVAL=$?
	echo ""
	return $RETVAL
}

# See how we were called.
case "$1" in
start)
	if [ $running -eq 0 ] ; then
		exit 0
	fi
	start
	;;
stop)
	if ! [ $running -eq 0 ] ; then
		exit 0
	fi
	stop
	;;
restart)
	stop
	start
	;;
status)
  	status -p $pidfile dtc-xen
	;;
condrestart)
	if ! [ $running -eq 0 ] ; then
		exit 0
	fi
	stop
	start
	;;
*)
	echo $"Usage: $0 {start|stop|restart|status|condrestart}"
	exit 2
esac

exit $?
