# dovecot - pop3/imap mail server
#
# Dovecot is a mail server whose major goals are security and extreme reliability.

description	"dovecot - pop3/imap mail server"

start on runlevel [2345]
stop on runlevel [!2345]

respawn

pre-start script
    test -x /usr/sbin/dovecot || { stop ; exit 0; }
    test -r /etc/dovecot/dovecot.conf || { stop ; exit 0; }

    # dont check for inetd.conf if its not installed
    if [ -f /etc/inetd.conf ]; then
      # The init script should do nothing if dovecot or another imap/pop3 server
      # is being run from inetd, and dovecot is configured to run as an imap or
      # pop3 service
      for p in `sed -r "s/^ *(([^:]+|\[[^]]+]|\*):)?(pop3s?|imaps?)[ \t].*/\3/;t;d" \
        /etc/inetd.conf`
      do
      for q in `sed -r "s/^[ \t]*protocols[ \t]*=[ \t]*(([^\"]*)|\"(.*)\")/\2\3/;t;d" \
         /etc/dovecot/dovecot.conf`
      do
        if [ $p = $q ]; then
          exit 0
        fi
      done
     done
   fi

end script

script
ulimit -n 5000
	test -x /usr/sbin/ntp-wait && ntp-wait -n 2 || true
	exec /usr/sbin/dovecot -F -c /etc/dovecot/dovecot.conf
end script
