#!/bin/bash
#
#	/etc/rc.d/init.d/dovecot
#
# Starts the dovecot daemon
#
# chkconfig: - 345 54 54
# description: Dovecot Imap Server
# processname: dovecot
# Source function library.
. /etc/init.d/functions

test -x /usr/sbin/dovecot || exit 0

RETVAL=0
prog="dovecot"

start() {
	echo -n $"Starting $prog: "
	# Check if dovecot is already running
	if [ ! -f /var/lock/subsys/dovecot ]; then
	    daemon /usr/sbin/dovecot
	    RETVAL=$?
	    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/dovecot
	    echo
	else
	    failure $"dovecot start"
	    echo
	fi
	return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc dovecot
	RETVAL=$?
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/dovecot
	echo
	return $RETVAL
}

#
#	See how we were called.
#
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  reload|restart)
	stop
	start
	;;
  condrestart)
	if [ -f /var/lock/subsys/dovecot ]; then
	    stop
	    start
	fi
	;;
  status)
	status /usr/sbin/dovecot
	;;
  *)
	echo $"Usage: $0 {condrestart|start|stop|restart|reload|status}"
	exit 1
esac

exit $?
