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