#!/bin/sh
#
# chkconfig: 345 87 07
# description: The squid is a HTTP/HTTPS/FTP/GOPHER/WAIS proxy server \
#	and cache. It accepts requests from network clients such as \
#	Netscape Navigator, and passes it to the proper hosts. The returned \
#	data are cached in a disk storage so that subsequent requests for \
#	the same URL can be answered via script without bothering the \
#	remote server.
#

# Source function library.
. /etc/rc.d/init.d/functions

test -r /etc/sysconfig/squid && . /etc/sysconfig/squid

SQUID_HOME=/usr

[ -f $SQUID_HOME/sbin/RunCache ] || exit 0

case "$1" in
  start)
     rm -f /var/run/squid.stop
     echo -n "Starting squid: "
     $SQUID_HOME/sbin/RunCache &
     echo 'squid(RunCache)'
     touch /var/lock/subsys/squid
     ;;
  stop)
     echo "Shutting down squid: "
     killproc RunCache
     if test -r /var/run/squid.pid
     then sqpid=`cat /var/run/squid.pid`
     fi
     killproc squid -TERM
     if [ "$sqpid" != "" ]
     then
	     echo "SIGTERM send to squid. Waiting for squid to finish."
	     echo -n "This can take few minutes - be patient, please: "
	     sleepcount=20
	     while [ "$sleepcount" -gt 0 ]
	     do
		kill -0 $sqpid 2>/dev/null || break
		echo -n "."
		sleep 10
		sleepcount=`expr $sleepcount - 1`
	     done
	     killproc squid
	     echo "Done."
     else
	     echo "Pid file not found. Squid is probably not running."
     fi
     rm -f /var/lock/subsys/squid
     ;;
  restart)
     echo -n "Restarting squid: "
     killproc squid -TERM
     echo "SIGTERM sent to squit. Restart may take a while."
     ;;
  status)
     status squid
     ;;
  *)
     echo "Usage: squid.init {start|stop}"
     exit 1
esac

exit 0
