#!/bin/bash
#
# Startup script for the DBMail Imap Server
#
# chkconfig: - 81 19
# description: DBMail is a mail server with a database backend. Unlike \
#	       WUimapd it does not run through inetd.
# processname: dbmail-imapd
# pidfile: /var/run/dbmail-imapd.pid
# config: /etc/dbmail.conf

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

if [ -f /etc/sysconfig/dbmail ]; then
        . /etc/sysconfig/dbmail
fi

# Path to the dbmail script.
dbmail=/usr/sbin/dbmail-imapd
prog=dbmail-imapd
RETVAL=0

start() {
        echo -n $"Starting $prog: "
        daemon --user dbmail $dbmail
        RETVAL=$?
        echo
        [ $RETVAL = 0 ] && touch /var/lock/subsys/$prog
        return $RETVAL
}
stop() {
	echo -n $"Stopping $prog: "
	killproc $dbmail
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/$prog /var/run/$prog.pid
}
reload() {
	echo -n $"Reloading $prog: "
	killproc $dbmail -HUP
	RETVAL=$?
	echo
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
        status $dbmail
	RETVAL=$?
	;;
  restart)
	stop
	start
	;;
  condrestart)
	if [ -f /var/run/$prog.pid ] ; then
		stop
		start
	fi
	;;
  reload)
        reload
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|condrestart|reload|status}"
	exit 1
esac

exit $RETVAL
