#!/bin/sh
#
# Startup script for dovecot
#

# Source function library.
. /usr/local/etc/rc.d/functions

PROG=/usr/sbin/dovecot
LOCK=/var/spool/lock/dovecot

RETVAL=0;

ulimit -HSn 32768

# See how we were called.
case "$1" in
  start)
        echo -n "Starting dovecot: "
        daemon $PROG
        RETVAL=$?
        if [ $RETVAL = 0 ] && touch $LOCK
        then
                echo -e "\t\t[ OK ]";
        else
                echo -e "\t\t[ FAILED ]";
        fi
        ;;
  stop)
        echo -n "Stopping dovecot: "
        kill `cat /var/run/dovecot/master.pid`
        RETVAL=$?
        if [ $RETVAL = 0 ] && rm -f $LOCK
        then
                echo -e "\t\t[ OK ]";
        else
                echo -e "\t\t[ FAILED ]";
        fi

        ;;
  status)
        status dovecot
        ;;
  restart)
        $0 stop
        sleep 1
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart|status}"
        exit 1
esac

exit $RETVAL
