cvsdist 509b2c2
#!/bin/bash
70a8119
### BEGIN INIT INFO
70a8119
# Provides: squid
cvsdist 509b2c2
# chkconfig: - 90 25
70a8119
# pidfile: /var/run/squid.pid
70a8119
# config: /etc/squid/squid.conf
70a8119
# Short-Description: starting and stopping Squid Internet Object Cache
70a8119
# Description: Squid - Internet Object Cache. Internet object caching is \
092433c
#       a way to store requested Internet objects (i.e., data available \
092433c
#       via the HTTP, FTP, and gopher protocols) on a system closer to the \
092433c
#       requesting site than to the source. Web browsers can then use the \
092433c
#       local Squid cache as a proxy HTTP server, reducing access time as \
092433c
#       well as bandwidth consumption.
70a8119
### END INIT INFO
70a8119
cvsdist 509b2c2
cvsdist 509b2c2
PATH=/usr/bin:/sbin:/bin:/usr/sbin
cvsdist 509b2c2
export PATH
cvsdist 509b2c2
cvsdist 509b2c2
# Source function library.
cvsdist 509b2c2
. /etc/rc.d/init.d/functions
cvsdist 509b2c2
cvsdist 509b2c2
# Source networking configuration.
cvsdist 509b2c2
. /etc/sysconfig/network
cvsdist 509b2c2
cvsdist a177a05
if [ -f /etc/sysconfig/squid ]; then
092433c
	. /etc/sysconfig/squid
cvsdist a177a05
fi
cvsdist a177a05
092433c
# don't raise an error if the config file is incomplete
cvsdist 3cd2d66
# set defaults instead:
cvsdist 3cd2d66
SQUID_OPTS=${SQUID_OPTS:-"-D"}
cvsdist 3cd2d66
SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
cvsdist 3cd2d66
SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
cvsdist 3cd2d66
cvsdist 509b2c2
# determine the name of the squid binary
cvsdist 509b2c2
[ -f /usr/sbin/squid ] && SQUID=squid
70a8119
3de4f62
if [ "$1" == "status" ]; then
70a8119
	[ -z "$SQUID" ] && exit 4
092433c
else
3f8f86c
	[ -z "$SQUID" ] && exit 1
70a8119
fi
cvsdist 509b2c2
cvsdist a177a05
prog="$SQUID"
cvsdist a177a05
cvsdist 509b2c2
# determine which one is the cache_swap directory
cvsdist 509b2c2
CACHE_SWAP=`sed -e 's/#.*//g' /etc/squid/squid.conf | \
092433c
	grep cache_dir | awk '{ print $3 }'`
cvsdist 509b2c2
[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/spool/squid
cvsdist 509b2c2
cvsdist 509b2c2
RETVAL=0
cvsdist 509b2c2
3f8f86c
probe() {
3f8f86c
	# Check that networking is up.
3f8f86c
	[ ${NETWORKING} = "no" ] && exit 1
3f8f86c
3f8f86c
	# check if the squid conf file is present
3f8f86c
	[ -f /etc/squid/squid.conf ] || exit 6
092433c
}
3f8f86c
cvsdist 509b2c2
start() {
3f8f86c
	probe
3f8f86c
092433c
	$SQUID -k parse
092433c
	RETVAL=$?
092433c
	if [ $RETVAL -ne 0 ]; then
092433c
		echo -n $"Starting $prog: "
092433c
		echo_failure
092433c
		echo
092433c
		return 1
092433c
	fi
092433c
	for adir in $CACHE_SWAP; do
092433c
		if [ ! -d $adir/00 ]; then
092433c
			echo -n "init_cache_dir $adir... "
092433c
			$SQUID -z -F -D >> /var/log/squid/squid.out 2>&1
3f8f86c
		fi
092433c
	done
092433c
	echo -n $"Starting $prog: "
092433c
	$SQUID $SQUID_OPTS >> /var/log/squid/squid.out 2>&1
092433c
	RETVAL=$?
092433c
	if [ $RETVAL -eq 0 ]; then
092433c
		timeout=0;
092433c
		while : ; do
092433c
			[ ! -f /var/run/squid.pid ] || break
092433c
			if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then
092433c
				RETVAL=1
092433c
				break
092433c
			fi
092433c
			sleep 1 && echo -n "."
092433c
			timeout=$((timeout+1))
092433c
		done
092433c
	fi
092433c
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID
092433c
	[ $RETVAL -eq 0 ] && echo_success
092433c
	[ $RETVAL -ne 0 ] && echo_failure
092433c
	echo
092433c
	return $RETVAL
cvsdist 509b2c2
}
cvsdist 509b2c2
cvsdist 509b2c2
stop() {
092433c
	echo -n $"Stopping $prog: "
092433c
	$SQUID -k check >> /var/log/squid/squid.out 2>&1
092433c
	RETVAL=$?
092433c
	if [ $RETVAL -eq 0 ] ; then
092433c
		$SQUID -k shutdown &
092433c
		rm -f /var/lock/subsys/$SQUID
092433c
		timeout=0
092433c
		while : ; do
092433c
			[ -f /var/run/squid.pid ] || break
092433c
			if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
092433c
				echo
092433c
				return 1
092433c
			fi
092433c
			sleep 2 && echo -n "."
092433c
			timeout=$((timeout+2))
092433c
		done
092433c
		echo_success
092433c
		echo
092433c
	else
092433c
		echo_failure
092433c
		echo
092433c
	fi
092433c
	return $RETVAL
092433c
}
cvsdist 509b2c2
cvsdist 509b2c2
reload() {
092433c
	$SQUID $SQUID_OPTS -k reconfigure
cvsdist 509b2c2
}
cvsdist 509b2c2
cvsdist 509b2c2
restart() {
092433c
	stop
092433c
	start
092433c
}
cvsdist 509b2c2
cvsdist 509b2c2
condrestart() {
092433c
	[ -e /var/lock/subsys/squid ] && restart || :
cvsdist 509b2c2
}
cvsdist 509b2c2
092433c
rhstatus() {
092433c
	status $SQUID && $SQUID -k check
cvsdist 509b2c2
}
cvsdist 509b2c2
cvsdist 509b2c2
cvsdist 509b2c2
case "$1" in
cvsdist 509b2c2
start)
092433c
	start
092433c
	;;
cvsdist 509b2c2
cvsdist 509b2c2
stop)
092433c
	stop
092433c
	;;
cvsdist 509b2c2
cvsdist 509b2c2
reload)
092433c
	reload
092433c
	;;
cvsdist 509b2c2
cvsdist 509b2c2
restart)
092433c
	restart
092433c
	;;
cvsdist 509b2c2
cvsdist 509b2c2
condrestart)
092433c
	condrestart
092433c
	;;
cvsdist 509b2c2
cvsdist 509b2c2
status)
092433c
	rhstatus
092433c
	;;
cvsdist 509b2c2
cvsdist 509b2c2
probe)
092433c
	probe
092433c
		return 0
092433c
	;;
cvsdist 509b2c2
cvsdist 509b2c2
*)
092433c
	echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|probe}"
092433c
	exit 2
cvsdist 509b2c2
esac
cvsdist 509b2c2
cvsdist 509b2c2
exit $?