squid/squid-initscript

110 lines
2.6 KiB
Bash

#!/bin/bash
#
# squid -- start/stop the Squid Internet Object Cache
#
# chkconfig: 345 90 25
# description: Squid HTTP Proxy
# pidfile: /var/run/squid.pid
# config: /etc/squid/squid.conf
. /etc/sysconfig/rc
# Source function library.
[ -r "$rc_functions" ] && . $rc_functions
NAME=squid
DAEMON=/usr/sbin/$NAME
DAEMONPID=/var/run/$NAME.pid
DAEMONCONF=/etc/squid/squid.conf
OPTIONS="-s"
[ -x $DAEMON ] || exit 0
# Source networking configuration.
[ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "yes" ] || exit 0
[ -r /etc/sysconfig/$NAME ] && . /etc/sysconfig/$NAME
[ "$SQUID_OPTIONS" ] && OPTIONS="$SQUID_OPTIONS"
# check if the squid conf file is present
[ -r $DAEMONCONF ] || exit 0
SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
# determine which one is the cache_swap directory
CACHE_SWAP=`sed -e 's/#.*//g' $DAEMONCONF | \
grep cache_dir | awk '{ print $3 }'`
[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/spool/squid
case "$1" in
start)
for d in $CACHE_SWAP; do
if [ -d $d -a ! -d $d/00 ]; then
echo -n "Creating swap directories $d... "
$DAEMON -z -F >> /var/log/squid/squid.out 2>&1
evaluate_retval; echo
fi
done
echo -n $"Starting $NAME: "
$DAEMON $OPTIONS >> /var/log/squid/squid.out 2>&1
#daemon --pidfile=$DAEMONPID $DAEMON $OPTIONS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$NAME
[ $RETVAL -eq 0 ] && echo_success || echo_failure
echo
;;
stop)
echo -n $"Stopping $NAME: "
$DAEMON -k check &> /dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
$DAEMON -k shutdown &
rm -f /var/lock/subsys/$NAME
timeout=0
echo -n $" Waiting"
while $DAEMON -k check &> /dev/null; do
if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
echo
return 1
fi
sleep 5 && echo -n "."
let timeout+=5
done
echo_success
echo
else
echo_success
echo
fi
;;
reload)
echo -n "Reloading $NAME: "
$DAEMON $OPTIONS -k reconfigure
evaluate_retval; echo
;;
restart)
$0 stop
sleep 1
$0 start
;;
condrestart)
[ -e /var/lock/subsys/$NAME ] && $0 restart || :
;;
status)
statusproc $DAEMON && $DAEMON -k check
;;
*)
echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
exit 1
;;
esac
exit $?