# squid This shell script takes care of starting and stopping
# Squid Internet Object Cache
#
-# chkconfig: 345 90 25
+# chkconfig: 345 90 10
#
# description: Squid - Internet Object Cache. Internet object caching is \
# a way to store requested Internet objects (i.e., data \
exit 0
fi
-# Sanity check
-[ -f /etc/squid/squid.conf ] || exit 0
+# Set default shutdown timeout if it is not set in service config
+SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-60}
-RETVAL=0
-# See how we were called.
-case "$1" in
- start)
+# determine which one is the cache_swap directory
+CACHE_SWAP=$(awk '/^cache_dir/{print $3}' /etc/squid/squid.conf)
+[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/cache/squid
+
+check_cache_dirs() {
+ local need_init=0 dir
+ for dir in $CACHE_SWAP; do
+ if [ ! -d $dir/00 ]; then
+ need_init=1
+ fi
+ done
+ if [ $need_init = 1 ]; then
+ show "Initializing Squid cache dirs"
+ squid -z -F -D >> /var/log/squid/squid.out 2>&1 && ok || fail
+ fi
+}
+
+start() {
# Check if the service is already running?
if [ ! -f /var/lock/subsys/squid ]; then
+ check_cache_dirs
msg_starting Squid
- daemon $SERVICE_RUN_NICE_LEVEL squid $SQUID_OPTS
+ daemon /usr/sbin/squid $SQUID_OPTS
RETVAL=$?
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/squid
else
msg_already_running Squid
fi
- ;;
- stop)
+}
+
+stop() {
if [ -f /var/lock/subsys/squid ]; then
# Stop daemons.
msg_stopping Squid
- if [ -f /var/run/httpd.pid ]; then
- PID=$(filter_chroot `cat /var/log/squid/squid.pid`)
- if [ -z "$PID" ]; then
- PID=0
- fi
- else
- PID=0
- fi
killproc squid
- RETVAL=$?
- if [ ! $PID -eq 0 ]; then
+
+ if [ -f /var/run/squid.pid ]; then
show "Waiting for Squid to stop"
busy
- while ps -U squid -o user | grep -q ^squid
- do
- sleep 1
+
+ timeout=0
+ while : ; do
+ [ ! -f /var/run/squid.pid ] || break
+ if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
+ RETVAL=1
+ break
+ fi
+ sleep 1 && echo -n "."
+ timeout=$((timeout+1))
done
ok
fi
+
rm -f /var/lock/subsys/squid >/dev/null 2>&1
else
msg_not_running Squid
fi
- ;;
- restart)
- $0 stop
- $0 start
- exit $?
- ;;
- reload|force-reload)
+}
+
+# check that squid config is ok
+configtest() {
+ show "Checking squid config syntax"
+ squid -k parse >> /var/log/squid/squid.out 2>&1
+ RETVAL=$?
+ [ $RETVAL = 0 ] && ok || fail
+}
+
+reload() {
if [ -f /var/lock/subsys/squid ]; then
msg_reloading Squid
busy
[ $RETVAL -ne 0 ] && RETVAL=7
[ $RETVAL -eq 0 ] && ok || fail
else
- msg_not_running Squid >&2
+ msg_not_running Squid
exit 7
fi
+}
+
+restart() {
+ # if service is up, do configtest
+ if [ -f /var/lock/subsys/squid ]; then
+ configtest
+ if [ $RETVAL != 0 ]; then
+ exit 1
+ fi
+ fi
+ stop
+ start
+}
+
+condrestart() {
+ # if service is up, do configtest
+ if [ -f /var/lock/subsys/squid ]; then
+ configtest
+ if [ $RETVAL != 0 ]; then
+ exit 1
+ fi
+ stop
+ start
+ else
+ msg_not_running Squid
+ RETVAL=0
+ fi
+}
+
+RETVAL=0
+# See how we were called.
+case "$1" in
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ restart
+ ;;
+ try-restart)
+ condrestart
+ ;;
+ reload|force-reload)
+ reload
;;
status)
status squid
exit $?
;;
init)
- nls "Initializing %s" squid
- squid -z
+ show "Initializing Squid"; echo
+ check_cache_dirs
;;
*)
- msg_usage "$0 {start|stop|init|restart|reload|force-reload|status}"
+ msg_usage "$0 {start|stop|init|restart|try-restart|reload|force-reload|status}"
exit 3
esac