#!/bin/sh
# Note: you can copy this script with other name for run another imapproxy instance (with separate config)
#
# chkconfig: - 85 15
# description: Imapproxy is a proxy for the IMAP protocol
# processname: in.imapproxyd
# config: /etc/imapproxy.conf

# Script Author: Simon Matter <simon.matter@invoca.ch>
# Version: 2003062600

# Do not load RH compatibility interface.
WITHOUT_RC_COMPAT=1

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

# Source networking configuration.
SourceIfNotEmpty /etc/sysconfig/network && [ "$NETWORKING" != no ] || exit

# This is our service name
NAME=`basename $0`
if [ -L $0 ]; then
  NAME=`find $0 -name $NAME -printf %l`
  NAME=`basename $NAME`
fi

CONFIG="/etc/${NAME}.conf"

[ -f "$CONFIG" ] || exit 1

RETVAL=0

DAEMON="/usr/sbin/in.imapproxyd"

PIDFILE="/var/run/$NAME.pid"
LOCKFILE="/var/lock/subsys/$NAME"
DUSER=nobody


start()
{
	start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$DUSER" -- "$DAEMON" -f "$CONFIG" -p "$PIDFILE"
	RETVAL=$?
	return $RETVAL
}

stop()
{
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --expect-user "$DUSER" -- "$DAEMON" -p "$PIDFILE"
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}


# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	reload)
		restart
		;;
	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 --pidfile "$PIDFILE" --expect-user "$DUSER" -- "$DAEMON"
		pimpstat -c
		RETVAL=$?
		;;
	*)
		msg_usage "${0##*/} {start|stop|reload|restart|condstop|condrestart|condreload|status}"
		RETVAL=1
esac


exit $RETVAL
