-#!/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
+# 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.
+# 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_no "${NETWORKING}"; then
+ msg_network_down Squid
+ exit 1
+fi
-# check if the squid conf file is present
+# Sanity check
[ -f /etc/squid/squid.conf ] || exit 0
-# define the cache_swap location
-CACHE_SWAP=/var/spool/squid
-
-# Try to define nice-level for running squid
-NICE="nice -n 5"
-
-# 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"
-
+# 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)
+ # Check if the service is already running?
+ if [ ! -f /var/lock/subsys/squid ]; then
+ msg_starting Squid
+ busy
+ daemon $SERVICE_RUN_NICE_LEVEL squid $SQUID_OPTS
+ RETVAL=$?
+ [ $RETVAL -eq 0 ] && touch /var/lock/subsys/squid
+ else
+ msg_already_running Squid
+ fi
+ ;;
+ stop)
+ # Stop daemons.
+ if [ -f /var/lock/subsys/squid ]; then
+ msg_stopping squid
+ killproc squid
+ rm -f /var/lock/subsys/squid >/dev/null 2>&1
+ else
+ msg_not_running squid
+ exit 1
+ fi
+ ;;
+ restart)
+ $0 stop
+ echo -n "Waiting 30 second..."
+ sleep 30
+ echo "done."
+ $0 start
+ ;;
+ reload)
+ if [ -f /var/lock/subsys/squid ]; then
+ msg_reloading squid
+ busy
+ squid -k reconfigure
+ ok
+ else
+ msg_not_running squid
+ exit 1
+ fi
+ ;;
+ status)
+ status squid
+ exit $?
+ ;;
+ init)
+ echo "Initializing squid"
+ squid -z
+ ;;
+ *)
+ msg_usage "$0 {start|stop|status|restart|reload|init}"
+ exit 1
esac
-exit 0
+exit $RETVAL