cat /etc/rc.d/rc.squid
#! /bin/sh
#
# squid         Startup script for the SQUID caching HTTP server.
#               This one is a bit different then usual because
#               a it has a shell script wrapper around it to watch
#               over it.
#
# Version:      @(#)squid.rc  1.30  17-Dec-1998  miquels@cistron.nl
#

PATH=/bin:/usr/bin:/sbin:/usr/sbin
DAEMON=/usr/local/squid/bin/RunCache
SQUID=/usr/local/squid/bin/squid
LIB=/usr/lib/squid
PIDFILE=/var/run/runcache.pid
SPIDFILE=/var/run/squid.pid
SQUID_ARGS="-s"

[ -x $SQUID ] || exit 0

start () {
        cd /usr/local/squid/bin/
        start-stop-daemon --quiet --start \
                --pidfile /var/run/runcache.pid \
                --exec $DAEMON -- $SQUID_ARGS < /dev/null &
        sleep 2
}

stop () {
        start-stop-daemon --stop --quiet --pidfile $PIDFILE
        start-stop-daemon --stop --quiet --pidfile $SPIDFILE --exec $SQUID
        #
        #       Now we have to wait until squid has _really_ stopped.
        #
        sleep 2
        if [ "`pidof -o %PPID -o $$ $SQUID`" != "" ]
        then
                echo -n "Waiting ."
                cnt=0
                while [ "`pidof -o %PPID -o $$ $SQUID`" != "" ]
                do
                        cnt=`expr $cnt + 1`
                        if [ $cnt -gt 60 ]
                        then
                                #
                                #       Waited 120 seconds now. Fail.
                                #
                                echo -n " Failed.. "
                                break
                        fi
                        sleep 2
                        echo -n "."
                done
                [ "$1" = verbose ] && echo "done."
        else
                [ "$1" = verbose ] && echo "squid."
        fi
}

case "$1" in
    start)
        echo -n "Starting proxy server: "
        start
        echo "squid."
        ;;
    stop)
        echo -n "Stopping proxy server: "
        stop verbose
        ;;
    reload|force-reload)
        echo "Reloading squid configuration files"
        start-stop-daemon --stop --signal 1 \
                --pidfile $SPIDFILE --quiet --exec $SQUID
        ;;
    restart)
        echo "Restarting proxy server: "
        stop
        start
        echo "squid."
        ;;
    *)
        echo "Usage: /etc/rc.d/squid {start|stop|reload|force-reload|restart}"
        exit 1
        ;;
esac

exit 0

