#! /bin/sh
#
# 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
#
# This file was customized by Y.Dirson on 2001-11-17

PATH=/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/sbin/xproxy
NAME=xproxy-server
DESC="XDFS server for low-bandwidth HTTP proxies"

CACHE=/var/cache/xproxy/servercache
LOGDIR=/var/log/xproxy-server

. /etc/default/xproxy-server || exit 0
[ -n "$PORT" ] || exit 0

# This setup resets the cache on every restart
# Working improvements welcomed
if true
then
    rm -rf ${CACHE} ${LOGDIR}
    CREATE="-c -L $LOGDIR"
fi

OPTIONS="server $CACHE $CREATE -p $PORT"

test -f $DAEMON || exit 0

start()
{
	start-stop-daemon --start --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON -- $OPTIONS
}
stop()
{
	start-stop-daemon --stop --quiet --pidfile /var/run/$NAME.pid \
		--exec $DAEMON
}

case "$1" in
  start)
	echo -n "Starting $DESC: "
	start
	echo "$NAME."
	;;
  stop)
	echo -n "Stopping $DESC: "
	stop
	echo "$NAME."
	;;
  restart|force-reload)
	#
	#	If the "reload" option is implemented, move the "force-reload"
	#	option to the "reload" entry above. If not, "force-reload" is
	#	just the same as "restart".
	#
	echo -n "Restarting $DESC: "
	stop
	sleep 1
	start
	echo "$NAME."
	;;
  *)
	N=/etc/init.d/$NAME
	echo "Usage: $N {start|stop|restart|force-reload}" >&2
	exit 1
	;;
esac

exit 0
