#!/bin/sh # # Control script for squid cache manager operation # Written by Andrei Boros, 03/22/2001 # E-mail : andrixnet@yahoo.com # Greetings to Marc Slemko, whose apachectl inspired this script # # Released under the GNU General Public License version 2 # See http://www.gnu.org/copyleft for details # # Errors levels returned by this script : # 0 - success # 1 - # 2 - usage error # 3 - squid not started, already running # 4 - squid not stopped, not running # 5 - squid could not be stopped # 6 - squid could not be started # 10 - reload attempt, but squid is not running # 11 - parsing configuration but squid is not running # 12 - failed to reconfigure squid. try a parse first. # # # Normally squid is reconfigured on the fly. I found no reason to # include a restart option # ########################################################################### # # # squid pid file SQUID_PID=/var/log/squid/squid.pid # # squid binary SQUID=/usr/local/squid/bin/squid # # squid configuration file. SQUIDCONF=/usr/local/squid/etc/squid.conf # # # squid defines a shutdown timeout to wait for sockets to close. For a clean # shutdown of the cache, we will issue a shutdown command then wait this many # seconds + 1 for this to complete. # A kill by rc.6 often leaves the PID file and squid won't start at next boot. HOWLONG=`cat $SQUIDCONF | grep "shutdown_lifetime" | cut -f 2 -d " "` HOWLONG2=`expr $HOWLONG + 2` # # ERROR=0 ARGV="$@" # # No parameters ? # if [ "x$ARGV" = "x" ]; then ARGS="help" fi for ARG in $@ $ARGS do # check for pid file if [ -f $SQUID_PID ]; then # PID file exists PID=`cat $SQUID_PID` if [ "x$PID" != "x" ]; then # PID exists if kill -0 $PID 2>/dev/null ; then # a process using PID is running if ps -p $PID -o args | grep squid > /dev/null 2>&1; then # that process is squid itself, OK STATUS="squid (pid $PID) running" RUNNING=1 else # squid not running, stale PID file contains PID of another # running process. No squid, remove the PID file rm -f $SQUID_PID STATUS="squid (stale pid file removed) not running" RUNNING=0 fi else # nothing using this PID. Remove file rm -f $SQUID_PID STATUS="squid (stale pid file removed) not running" RUNNING=0 fi else # PID file is empty. Squid not running, remove file. rm -f $SQUID_PID STATUS="squid (stale pid file removed) not running" RUNNING=0 fi else # No PID file, not running. STATUS="squid (no pid) not running" RUNNING=0 fi case $ARG in parse) if [ $RUNNING -eq 0 ]; then echo "$0 $ARG: squid (pid $PID) not running" ERROR=11 continue fi # # Parse squid configuration. Errors are allowed, it is the purpose of this command # $SQUID -k parse ;; reload) if [ $RUNNING -eq 0 ]; then echo "$0 $ARG: squid (pid $PID) not running" ERROR=10 continue fi if $SQUID -k reconfigure ; then echo "$0 $ARG: squid (pid $PID) reconfigured" else echo "$0 $ARG: unable to reconfigure squid (pid $PID)" ERROR=12 fi ;; stop) if [ $RUNNING -eq 0 ]; then echo "$0 $ARG: $STATUS" ERROR=4 continue fi # # Don't know why a simple kill doesn't always work. PID file and other things # remain and squid will refuse to start. # # This is the proper way to stop squid. Put this in your shutdown scripts # if $SQUID -k shutdown ; then echo "Squid is shutting down. Waiting $HOWLONG2 seconds for cleanup..." sleep $HOWLONG2 s # # Is squid PID file still present ? (It shouldn't) # if [ -f $SQUID_PID ]; then echo "$0 $ARG: failed to stop squid (pid $PID)" ERROR=5 continue else echo "$0 $ARG: squid (pid $PID) stopped" fi else echo "$0 $ARG: failed to shutdown squid (pid $PID)" ERROR=5 continue fi ;; start) if [ $RUNNING -eq 1 ]; then echo "$0 $ARG: squid (pid $PID) already running" ERROR=3 continue fi if $SQUID ; then echo "$0 $ARG: squid started" else echo "$0 $ARG: starting squid failed" ERROR=6 fi ;; status) echo $STATUS continue ;; help) echo "usage: $0 (start|stop|reload|parse|status|help)" cat <