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