#!/bin/sh
#
# imapd         This shell script takes care of starting and stopping
#              imapd (cyrus master daemon wrapper).
#
# chkconfig: 2345 55 10
# description: imapd is the Cyrus imap daemon.

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -x /usr/libexec/cyrus/bin/master ] || exit 0

# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting Cyrus imapd: "
        /usr/libexec/cyrus/bin/master &
        evaluate_retval
	echo
        touch /var/lock/subsys/cyrus
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down Cyrus imapd: "
        killproc master
	evaluate_retval
	echo
        rm -f /var/lock/subsys/cyrus
        ;;
  status)
        status master
        ;;
  restart)
        $0 stop
        $0 start
        ;;
  reload)
        $0 stop
        $0 start
        ;;
  condrestart)
    if [ -f /var/lock/subsys/cyrus ]; then
        $0 stop
        $0 start
    fi
    ;;
  *)
        echo "Usage: imapd {start|stop|restart|status}"
        exit 1
esac

exit 0
