#!/bin/bash
#
# up-imapproxy: Starts the University of Pittsburgh IMAP Proxy
#
# chkconfig: - 75 25
# description: imapproxy was written to compensate for webmail clients that \
#              are unable to maintain persistent connections to an IMAP \
#              server. Most webmail clients need to log in to an IMAP server \
#              for nearly every single transaction. This behaviour can cause \
#              tragic performance problems on the IMAP server. imapproxy \
#              tries to deal with this problem by leaving server connections \
#              open for a short time after a webmail client logs out. When \
#              the webmail client connects again, imapproxy will determine if \
#              there's a cached connection available and reuse it if possible.
# processname: in.imapproxyd
# config: /etc/imapproxy.conf

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

. /etc/sysconfig/network

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

start() {
	echo -n $"Starting imapproxyd: "
	daemon /usr/sbin/in.imapproxyd
	RETVAL=$?
	echo
	touch $lockfile
	return $RETVAL
}

stop() {
	echo -n $"Shutting down imapproxyd: "
	killproc /usr/sbin/in.imapproxyd
	RETVAL=$?
	if [ $RETVAL -eq 0 ] ; then
	    rm -f $lockfile
	fi
	echo
	return $RETVAL
}

restart() {
	stop
	start
}

RETVAL=0
lockfile=/var/lock/subsys/imapproxy

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

exit $?
