#!/bin/sh
#
# This is file /etc/rc.d/init.d/squid
#
# description: web proxy cache
#  ********************************************************************
# 
#  Purpose     :  This shell script takes care of starting and stopping
#                 squid.
# 
# ********************************************************************/

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

. /etc/sysconfig/network

#  Check that networking is up.
if [ "${NETWORKING}" = "no" ]; then exit 0; fi

start () {
	if [ ! -d /mnt/squid/logs ]; then
          mkdir -p /mnt/squid/logs
	  chown -R nobody:nobody /mnt/squid/logs
        fi
	if [ ! -d /mnt/squid/cache ]; then
          mkdir -p /mnt/squid/cache
	  chown -R nobody:nobody /mnt/squid/cache
        fi
	if [ ! -d /mnt/squid/cache/00 ]; then
          /usr/sbin/squid -z
        fi
	echo -n $"Starting Squid: "
	/usr/sbin/squid -D
	RETVAL=$?
	echo
	return $RETVAL
}

stop () {
	echo -n $"Stopping Squid: "
	/usr/sbin/squid -k shutdown
	RETVAL=$?
	echo
	return $RETVAL
}

case "$1" in
  start)
	start	
	;;
  stop)
	stop
	;;
  reload)
	/usr/sbin/squid -k reconfigure
        RETVAL=$?
	;;
  restart)
	stop
	start
	RETVAL=$?
	;;
  rotate)
	/usr/sbin/squid -k rotate
	RETVAL=$?
	;;
  *)
	echo $"Usage: squid {start|stop|reload|restart|rotate}"
	exit 1
esac

exit $RETVAL
