-#!/bin/bash
+#!/bin/sh
+#
# squid This shell script takes care of starting and stopping
# Squid Internet Object Cache
#
-# chkconfig: 345 90 25
-# description: Squid - Internet Object Cache. Internet object caching is \
-# a way to store requested Internet objects (i.e., data available \
-# via the HTTP, FTP, and gopher protocols) on a system closer to the \
-# requesting site than to the source. Web browsers can then use the \
-# local Squid cache as a proxy HTTP server, reducing access time as \
-# well as bandwidth consumption.
-# pidfile: /var/run/squid.pid
-# config: /etc/squid/squid.conf
-
-# Source function library.
+# chkconfig: 345 90 10
+#
+# description: Squid - Internet Object Cache. Internet object caching is \
+# a way to store requested Internet objects (i.e., data \
+# available via the HTTP, FTP, and gopher protocols) on a \
+# system closer to the requesting site than to the source. \
+# Web browsers can then use the local Squid cache as a proxy \
+# HTTP server, reducing access time as well as bandwidth \
+# consumption.
+# description(es): Squid - Cache de Objetos de Internet. Cache de objetos \
+# es una manera de almacenar objetos Internet (i.e. Datos \
+# disponibles vía protocolos HTTP, FTP y gopher) en un \
+# sistema más próximo al site solicitador que el sistema \
+# original en internet. Navegadores www pueden usar el \
+# cache squid local como un servidor proxy HTTP, reduciendo \
+# tanto el tiempo de acceso así como el consumo de banda de \
+# comunicación.
+# description(pt_BR): Squid - Cache de Objetos da Internet. Cache de objetos \
+# é uma maneira de armazenar objetos Internet (i.e. dados \
+# disponíveis via protocolos HTTP, FTP e gopher) em um \
+# sistema mais próximo ao site requisitante do que o sistema \
+# original na internet. Navegadores www podem usar o cache \
+# squid local como um servidor proxy HTTP, reduzindo o tempo \
+# de acesso bem como o consumo de banda de comunicação.
+#
+# pidfile: /var/run/squid.pid
+# config: /etc/squid/squid.conf
+
+
+# Source function library
. /etc/rc.d/init.d/functions
-# Source networking configuration.
+# Get network config
. /etc/sysconfig/network
+# Get service config
+[ -f /etc/sysconfig/squid ] && . /etc/sysconfig/squid
+
# Check that networking is up.
-[ "${NETWORKING}" = "no" ] && exit 0
+if is_yes "${NETWORKING}"; then
+ if [ ! -f /var/lock/subsys/network -a "$1" != stop -a "$1" != status -a "$1" != init ]; then
+ msg_network_down Squid
+ exit 1
+ fi
+else
+ exit 0
+fi
+
+# Set default shutdown timeout if it is not set in service config
+SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-60}
+
+# 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 /usr/sbin/squid $SQUID_OPTS
+ RETVAL=$?
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/squid
+ else
+ msg_already_running Squid
+ fi
+}
+
+stop() {
+ if [ -f /var/lock/subsys/squid ]; then
+ # Stop daemons.
+ msg_stopping Squid
+ killproc squid
+
+ if [ -f /var/run/squid.pid ]; then
+ show "Waiting for Squid to stop"
+ busy
+
+ 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
+}
-# check if the squid conf file is present
-[ -f /etc/squid/squid.conf ] || exit 0
+# 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
+}
-# define the cache_swap location
-CACHE_SWAP=/var/spool/squid
+reload() {
+ if [ -f /var/lock/subsys/squid ]; then
+ msg_reloading Squid
+ busy
+ squid -k reconfigure
+ RETVAL=$?
+ [ $RETVAL -ne 0 ] && RETVAL=7
+ [ $RETVAL -eq 0 ] && ok || fail
+ else
+ msg_not_running Squid
+ exit 7
+ fi
+}
-# Try to define nice-level for running squid
-NICE="nice -n 5"
+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
+}
-# default squid options
-# -D disables initial dns checks. If you most likely will not to have an
-# internet connection when you start squid, uncomment this
-#SQUID_OPTS="-D"
+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)
- show Starting squid
- busy
- if [ ! -d $CACHE_SWAP/00 ]; then
- squid -z -F &>/dev/null
- fi
- $NICE squid $SQUID_OPTS &
- touch /var/lock/subsys/squid
- deltext;ok
- ;;
-stop)
- show Stopping squid
- killproc squid
- rm -f /var/lock/subsys/squid
- ;;
-restart)
- $0 stop
- $0 start
- ;;
-status)
- status squid
- ;;
-*)
- echo "Usage: $0 {start|stop|status|restart}"
- exit 1
+ start)
+ start
+ ;;
+ stop)
+ stop
+ ;;
+ restart)
+ restart
+ ;;
+ try-restart)
+ condrestart
+ ;;
+ reload|force-reload)
+ reload
+ ;;
+ status)
+ status squid
+ exit $?
+ ;;
+ init)
+ show "Initializing Squid"; echo
+ check_cache_dirs
+ ;;
+ *)
+ msg_usage "$0 {start|stop|init|restart|try-restart|reload|force-reload|status}"
+ exit 3
esac
-exit 0
+exit $RETVAL