File rc.squid of Package squid3.import5582

#! /bin/sh
# Copyright (c) 1996, 1997, 1998 S.u.S.E. GmbH
# Copyright (c) 1998, 1999, 2000, 2001 SuSE GmbH
# Copyright (c) 2002 SuSE Linux AG
#
# Author: Frank Bodammer, Peter Poeml, Klaus Singvogel <feedback@suse.de>
#
# init.d/squid
#
### BEGIN INIT INFO
# Provides:			squid
# Required-Start:		$local_fs $remote_fs $network $time
# Should-Start:			apache $named 
# Required-Stop:		$local_fs $remote_fs $network
# Should-Stop:			$null
# Default-Start:		3 5
# Default-Stop:			0 1 2 6
# Short-Description:		Squid web cache
# Description:			Start the Squid web cache, providing
#				HTTP, FTP and other proxy services
### END INIT INFO


SQUID_BIN=/usr/sbin/squid
SQUID_PID=/var/run/squid.pid
SQUID_CONF=/etc/squid/squid.conf
SQUID_SYSCONFIG=/etc/sysconfig/squid

if [ ! -x $SQUID_BIN ] ; then
	echo -n "WWW-proxy squid not installed ! "
	exit 5
fi

# check for squid
test -r $SQUID_SYSCONFIG || { echo "$SQUID_SYSCONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0; else exit 6; fi; }

# Read config
. $SQUID_SYSCONFIG

# handle a special update case for unpopulated sysconfig data 
test -z "$SQUID_SHUTDOWN_TIMEOUT" && SQUID_SHUTDOWN_TIMEOUT="60"

. /etc/rc.status
RC_OPTIONS='-v'
rc_reset

ulimit -n 4096

# determine which one is the cache_swap directory
CACHE_SWAP=`perl -n -e \
 '/^cache_dir\s+\S+\s+(.*)\s+\d+\s+\d+\s+\d+/ && print "\$1 "' $SQUID_CONF`
[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/cache/squid

case "$1" in
    start)
	echo -n "Starting WWW-proxy squid "
	checkproc $SQUID_BIN
	if [ $? -eq 0 ] ; then
	   echo -n "- Warning: squid already running ! "
	   rc_failed
	else
	   [ -e $SQUID_PID ] && echo -n "- Warning: $SQUID_PID exists ! "
	   for adir in $CACHE_SWAP ; do
	     if [ ! -d $adir/00 ]; then # create missing cache directories
	        umask 027             # prevent users reading any cache data
	        echo -n " ($adir)"
	        $SQUID_BIN -z -F > /dev/null 2>&1
	     fi
	     if [ ! -d $adir/00 ]; then
	        echo " - failed while creating cache_dir ! "
	        rc_failed
		rc_status -v
		rc_exit
	     fi
	   done
	   sleep 2
	fi
	startproc -l /var/log/squid/rcsquid.log $SQUID_BIN -sYD
	rc_status $RC_OPTIONS
	;;
    stop)
	echo -n "Shutting down WWW-proxy squid "
	if checkproc $SQUID_BIN ; then
	   $SQUID_BIN -k shutdown
	   sleep 2
	   if [ -e $SQUID_PID ] ; then 
	      echo -n "- wait a minute or two... "
	      i="$SQUID_SHUTDOWN_TIMEOUT"
	      while [ -e $SQUID_PID ] && [ $i -gt 0 ] ; do
	         sleep 2
	         i=$[$i-1]
	         echo -n "."
	         [ $i -eq 41 ] && echo
	      done
	   fi
	   if checkproc $SQUID_BIN ; then
	      killproc -TERM $SQUID_BIN
	      echo -n " Warning: squid killed !"
	   fi
	else
	   echo -n "- Warning: squid not running ! "
	   rc_failed 7
	fi
	rc_status -v
	;;
    try-restart)
	$0 status >/dev/null && $0 restart
	rc_status
	;;
    restart)
	$0 stop
	$0 start
	rc_status
	;;
    force-reload)
	$0 reload
	rc_status
	;;
    reload)
	echo -n "Reloading WWW-proxy squid "
	if checkproc $SQUID_BIN ; then
	   $SQUID_BIN -k rotate
	   sleep 2
	   $SQUID_BIN -k reconfigure
	   rc_status
	else
	   echo -n "- Warning: squid not running ! "
	   rc_failed 7
	fi
	rc_status -v
	;;
    status)
        echo -n "Checking for WWW-proxy squid "
        checkproc $SQUID_BIN
        rc_status -v
        ;;
    probe)
	test $SQUID_CONF -nt $SQUID_PID && echo reload
	;;
    *)
	echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
	exit 1
	;;
esac
rc_exit