#! /bin/sh
# Initfile for imapproxy
#
# skeleton	example file to build /etc/init.d/ scripts.
#		This file should be used to construct scripts for /etc/init.d.
#
#		Written by Miquel van Smoorenburg <miquels@cistron.nl>.
#		Modified for Debian GNU/Linux
#		by Ian Murdock <imurdock@gnu.ai.mit.edu>.
#
# Version:	@(#)skeleton  1.8  03-Mar-1998  miquels@cistron.nl
# Customized for UP-ImapProxy by Jose Luis Tallon <jltallon@adv-solutions.net>

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/imapproxyd
ARGS="-f /etc/imapproxy.conf"
NAME="imapproxy"
DESC="IMAP proxy"

test -f $DAEMON || exit 0

set -e

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start-stop-daemon --start --quiet \
		--exec $DAEMON -- $ARGS
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	start-stop-daemon --oknodo --stop --quiet \
		--exec $DAEMON -- $ARGS
	sleep 1
        if [ -n "`ps ax | grep imapproxyd`" ]; then
                killall -15 imapproxyd >/dev/null 2>&1 || true
        fi

	echo "$NAME."
	
	;;

  restart|force-reload)
	echo -n "Restarting $DESC: "
	$0 stop
	sleep 1
	$0 start
	#echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
