#!/bin/sh
#
# dovecot	Dovecot secure IMAP server
#
# chkconfig: 35 70 30
# description:	Security is the major goal of this project, \
#		with reliability coming second.
#
# processname: dovecot
# child processes: imap, imap-auth, imap-login
# config: /etc/dovecot.conf
# pidfile: none

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

#PIDFILE=/var/run/dovecot.pid
LOCKFILE=/var/lock/subsys/dovecot
RETVAL=0

start()
{
	msg_starting "Dovecot secure IMAP server"
	start_daemon --lockfile "$LOCKFILE" --no-announce --expect-user root -- dovecot
	RETVAL=$?
	return $RETVAL
}

stop()
{
	msg_stopping "Dovecot secure IMAP server"
	stop_daemon --lockfile "$LOCKFILE" --no-announce --expect-user root -- dovecot
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading dovecot
	stop_daemon --lockfile "$LOCKFILE" --expect-user root -HUP -- dovecot
	RETVAL=$?
	return $RETVAL
} 

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		reload
		;;
	restart)
		restart
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	status)
		status --expect-user root -- dovecot
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac

exit $RETVAL
