#!/bin/sh
#
# start-squid.sample,v 1.2 1998/07/24 23:58:32 dlu Exp
#
# Run squid in a known environment.  This is the place to adjust system
# resource limits if you are running a particulaly big or busy cache.
# You probably also want to review the settings in your configuation file.

HOME=/var/www/squid
LOGNAME=www
NAME="Squid HTTP Proxy"
PATH=/usr/bin:/bin:/usr/contrib/bin
USER=$LOGNAME
export HOME LOGNAME NAME PATH USER

cd $HOME

# This is pretty restrictive, but if you are using cachemgr.cgi
# passwords will be logged in /var/log/squid/access.log.
umask 077

# Set resource limits.  These values set an upper bound on squid's
# resource consumption and will need to be changed if you increase the
# limits in you configuration file (/var/www/conf/squid.conf by default).
#
limit datasize  32768 kilobytes
limit openfiles 4096
limit memoryuse 14520 kilobytes

# Start squid, it will run until shutdown (either naturally or not).
# 
if [ -d $HOME/cache/0F/FF ]
then
	daemon squid
else
	echo "Initializing squid cache directories, this will take a while . . ."
	squid -z
	echo "done initializing cache, starting squid."
	daemon squid
fi

# If you are having problems with squid exiting you may find it helpful
# to run squid from a loop like the one below, while you track down the
# problem.  Save the section below in another file and start it in the
# background from this file.
#
# Starting squid from a loop has the advantage that you cache is less
# likely to be down, and the disadvantage that you're less likely to
# notice problems.
#
#	failcount=0
#	while : ; do
#		start=`date '+%d%H%M%S'`
#		squid
#		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
#			logger "squid shut down due to frequent, repeated, failures"
#			exit 1
#		fi
#		sleep 10
#	done
