#!/bin/sh
#
#  $Id: RunCache.in,v 1.3.2.4 1996/05/24 06:40:39 wessels Exp $

prefix=/usr/lib/squid
exec_prefix=${prefix}
[ "$logdir" = "" ] && logdir=$prefix
PATH=${exec_prefix}:/bin:/sbin:/usr/sbin:/usr/bin
export PATH

exec 3>>$logdir/squid.out

conf=""
if test "$1" ; then
	conf="-f $1"
	shift
fi

failcount=0
while : ; do
	echo "`date`: Running: squid -D -s $conf >> $logdir/squid.out 2>&1" >&3
	echo "`date`: Running: squid -D -s $conf >> $logdir/squid.out 2>&1"
	start=`date '+%d%H%M%S'`
	squid -D -s $conf 1>&3 2>&3
	stop=`date '+%d%H%M%S'`
	t=`expr $stop - $start`
	if test 0 -le $t -a $t -lt 5 ; then
		failcount=`expr $failcount + 1`
	else
		failcount=0
	fi
	if test $failcount -gt 5 ; then
          echo "`date`: RunCache: EXITING DUE TO REPEATED FREQUENT FAILURES" >&2
          echo "`date`: RunCache: EXITING DUE TO REPEATED FREQUENT FAILURES" >&3
	  exit 1
	fi
	sleep 10
done
