2004-09-09 12:36:11 +00:00
|
|
|
#!/bin/bash
|
2007-07-19 20:42:07 +00:00
|
|
|
### BEGIN INIT INFO
|
|
|
|
# Provides: squid
|
2004-09-09 12:36:11 +00:00
|
|
|
# chkconfig: - 90 25
|
2007-07-19 20:42:07 +00:00
|
|
|
# pidfile: /var/run/squid.pid
|
|
|
|
# config: /etc/squid/squid.conf
|
|
|
|
# Short-Description: starting and stopping Squid Internet Object Cache
|
|
|
|
# Description: Squid - Internet Object Cache. Internet object caching is \
|
2008-03-13 13:23:15 +00:00
|
|
|
# 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.
|
2007-07-19 20:42:07 +00:00
|
|
|
### END INIT INFO
|
|
|
|
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
PATH=/usr/bin:/sbin:/bin:/usr/sbin
|
|
|
|
export PATH
|
|
|
|
|
|
|
|
# Source function library.
|
|
|
|
. /etc/rc.d/init.d/functions
|
|
|
|
|
|
|
|
# Source networking configuration.
|
|
|
|
. /etc/sysconfig/network
|
|
|
|
|
2004-09-09 12:36:20 +00:00
|
|
|
if [ -f /etc/sysconfig/squid ]; then
|
2008-03-13 13:23:15 +00:00
|
|
|
. /etc/sysconfig/squid
|
2004-09-09 12:36:20 +00:00
|
|
|
fi
|
|
|
|
|
2008-03-13 13:23:15 +00:00
|
|
|
# don't raise an error if the config file is incomplete
|
2004-09-09 12:41:10 +00:00
|
|
|
# set defaults instead:
|
|
|
|
SQUID_OPTS=${SQUID_OPTS:-"-D"}
|
|
|
|
SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
|
|
|
|
SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
|
2008-10-08 06:45:52 +00:00
|
|
|
SQUID_CONF=${SQUID_CONF:-"/etc/squid/squid.conf"}
|
2004-09-09 12:41:10 +00:00
|
|
|
|
2004-09-09 12:36:11 +00:00
|
|
|
# determine the name of the squid binary
|
|
|
|
[ -f /usr/sbin/squid ] && SQUID=squid
|
2007-07-19 20:42:07 +00:00
|
|
|
|
2004-09-09 12:36:20 +00:00
|
|
|
prog="$SQUID"
|
|
|
|
|
2004-09-09 12:36:11 +00:00
|
|
|
# determine which one is the cache_swap directory
|
2008-10-08 06:45:52 +00:00
|
|
|
CACHE_SWAP=`sed -e 's/#.*//g' $SQUID_CONF | \
|
2008-03-13 13:23:15 +00:00
|
|
|
grep cache_dir | awk '{ print $3 }'`
|
2004-09-09 12:36:11 +00:00
|
|
|
[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/var/spool/squid
|
|
|
|
|
|
|
|
RETVAL=0
|
|
|
|
|
2007-07-24 14:32:02 +00:00
|
|
|
probe() {
|
|
|
|
# Check that networking is up.
|
|
|
|
[ ${NETWORKING} = "no" ] && exit 1
|
|
|
|
|
2009-04-28 09:11:55 +00:00
|
|
|
[ `id -u` -ne 0 ] && exit 4
|
2008-10-08 06:45:52 +00:00
|
|
|
|
2007-07-24 14:32:02 +00:00
|
|
|
# check if the squid conf file is present
|
2008-10-08 06:45:52 +00:00
|
|
|
[ -f $SQUID_CONF ] || exit 6
|
2008-03-13 13:23:15 +00:00
|
|
|
}
|
2007-07-24 14:32:02 +00:00
|
|
|
|
2004-09-09 12:36:11 +00:00
|
|
|
start() {
|
2007-07-24 14:32:02 +00:00
|
|
|
probe
|
|
|
|
|
2008-10-08 06:45:52 +00:00
|
|
|
parse=`$SQUID -k parse -f $SQUID_CONF 2>&1`
|
2008-03-13 13:23:15 +00:00
|
|
|
RETVAL=$?
|
|
|
|
if [ $RETVAL -ne 0 ]; then
|
|
|
|
echo -n $"Starting $prog: "
|
|
|
|
echo_failure
|
|
|
|
echo
|
2008-10-08 06:45:52 +00:00
|
|
|
echo "$parse"
|
2008-03-13 13:23:15 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
for adir in $CACHE_SWAP; do
|
|
|
|
if [ ! -d $adir/00 ]; then
|
|
|
|
echo -n "init_cache_dir $adir... "
|
|
|
|
$SQUID -z -F -D >> /var/log/squid/squid.out 2>&1
|
2007-07-24 14:32:02 +00:00
|
|
|
fi
|
2008-03-13 13:23:15 +00:00
|
|
|
done
|
|
|
|
echo -n $"Starting $prog: "
|
2008-10-08 06:45:52 +00:00
|
|
|
$SQUID $SQUID_OPTS -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1
|
2008-03-13 13:23:15 +00:00
|
|
|
RETVAL=$?
|
|
|
|
if [ $RETVAL -eq 0 ]; then
|
|
|
|
timeout=0;
|
|
|
|
while : ; do
|
|
|
|
[ ! -f /var/run/squid.pid ] || break
|
|
|
|
if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then
|
|
|
|
RETVAL=1
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
sleep 1 && echo -n "."
|
|
|
|
timeout=$((timeout+1))
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID
|
|
|
|
[ $RETVAL -eq 0 ] && echo_success
|
|
|
|
[ $RETVAL -ne 0 ] && echo_failure
|
|
|
|
echo
|
|
|
|
return $RETVAL
|
2004-09-09 12:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2008-03-13 13:23:15 +00:00
|
|
|
echo -n $"Stopping $prog: "
|
2008-10-08 06:45:52 +00:00
|
|
|
$SQUID -k check -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1
|
2008-03-13 13:23:15 +00:00
|
|
|
RETVAL=$?
|
|
|
|
if [ $RETVAL -eq 0 ] ; then
|
2008-10-08 06:45:52 +00:00
|
|
|
$SQUID -k shutdown -f $SQUID_CONF &
|
2008-03-13 13:23:15 +00:00
|
|
|
rm -f /var/lock/subsys/$SQUID
|
|
|
|
timeout=0
|
|
|
|
while : ; do
|
|
|
|
[ -f /var/run/squid.pid ] || break
|
|
|
|
if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
|
|
|
|
echo
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
sleep 2 && echo -n "."
|
|
|
|
timeout=$((timeout+2))
|
|
|
|
done
|
|
|
|
echo_success
|
|
|
|
echo
|
|
|
|
else
|
|
|
|
echo_failure
|
|
|
|
echo
|
|
|
|
fi
|
|
|
|
return $RETVAL
|
|
|
|
}
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
reload() {
|
2008-10-08 06:45:52 +00:00
|
|
|
$SQUID $SQUID_OPTS -k reconfigure -f $SQUID_CONF
|
2004-09-09 12:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
restart() {
|
2008-03-13 13:23:15 +00:00
|
|
|
stop
|
|
|
|
start
|
|
|
|
}
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
condrestart() {
|
2008-03-13 13:23:15 +00:00
|
|
|
[ -e /var/lock/subsys/squid ] && restart || :
|
2004-09-09 12:36:11 +00:00
|
|
|
}
|
|
|
|
|
2008-03-13 13:23:15 +00:00
|
|
|
rhstatus() {
|
2008-10-08 06:45:52 +00:00
|
|
|
status $SQUID && $SQUID -k check -f $SQUID_CONF
|
2004-09-09 12:36:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
start)
|
2008-03-13 13:23:15 +00:00
|
|
|
start
|
|
|
|
;;
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
stop)
|
2008-03-13 13:23:15 +00:00
|
|
|
stop
|
|
|
|
;;
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
reload)
|
2008-03-13 13:23:15 +00:00
|
|
|
reload
|
|
|
|
;;
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
restart)
|
2008-03-13 13:23:15 +00:00
|
|
|
restart
|
|
|
|
;;
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
condrestart)
|
2008-03-13 13:23:15 +00:00
|
|
|
condrestart
|
|
|
|
;;
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
status)
|
2008-03-13 13:23:15 +00:00
|
|
|
rhstatus
|
|
|
|
;;
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
probe)
|
2008-03-13 13:23:15 +00:00
|
|
|
probe
|
|
|
|
return 0
|
|
|
|
;;
|
2004-09-09 12:36:11 +00:00
|
|
|
|
|
|
|
*)
|
2008-03-13 13:23:15 +00:00
|
|
|
echo $"Usage: $0 {start|stop|status|reload|restart|condrestart|probe}"
|
|
|
|
exit 2
|
2004-09-09 12:36:11 +00:00
|
|
|
esac
|
|
|
|
|
|
|
|
exit $?
|