Blame | Last modification | View Log | RSS feed
#!/bin/bash# chkconfig: - 90 25# pidfile: /var/run/squid.pid# config: /etc/squid/squid.conf#### BEGIN INIT INFO# Provides: squid# Short-Description: starting and stopping Squid Internet Object Cache# 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.### END INIT INFOPATH=/usr/bin:/sbin:/bin:/usr/sbinexport PATH# Source function library.. /etc/rc.d/init.d/functions# Source networking configuration.. /etc/sysconfig/networkif [ -f /etc/sysconfig/squid ]; then. /etc/sysconfig/squidfi# don't raise an error if the config file is incomplete# set defaults instead:SQUID_OPTS=${SQUID_OPTS:-""}SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}SQUID_CONF=${SQUID_CONF:-"/etc/squid/squid.conf"}# determine the name of the squid binary[ -f /usr/sbin/squid ] && SQUID=squidprog="$SQUID"# determine which one is the cache_swap directoryCACHE_SWAP=`sed -e 's/#.*//g' $SQUID_CONF | \grep cache_dir | awk '{ print $3 }'`RETVAL=0probe() {# Check that networking is up.[ ${NETWORKING} = "no" ] && exit 1[ `id -u` -ne 0 ] && exit 4# check if the squid conf file is present[ -f $SQUID_CONF ] || exit 6}start() {probeparse=`$SQUID -k parse -f $SQUID_CONF 2>&1`RETVAL=$?if [ $RETVAL -ne 0 ]; thenecho -n $"Starting $prog: "echo_failureechoecho "$parse"return 1fifor adir in $CACHE_SWAP; doif [ ! -d $adir/00 ]; thenecho -n "init_cache_dir $adir... "$SQUID -z -F -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1fidoneecho -n $"Starting $prog: "$SQUID $SQUID_OPTS -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1RETVAL=$?if [ $RETVAL -eq 0 ]; thentimeout=0;while : ; do[ ! -f /var/run/squid.pid ] || breakif [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; thenRETVAL=1breakfisleep 1 && echo -n "."timeout=$((timeout+1))donefi[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID[ $RETVAL -eq 0 ] && echo_success[ $RETVAL -ne 0 ] && echo_failureechoreturn $RETVAL}stop() {echo -n $"Stopping $prog: "$SQUID -k check -f $SQUID_CONF >> /var/log/squid/squid.out 2>&1RETVAL=$?if [ $RETVAL -eq 0 ] ; then$SQUID -k shutdown -f $SQUID_CONF &rm -f /var/lock/subsys/$SQUIDtimeout=0while : ; do[ -f /var/run/squid.pid ] || breakif [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; thenechoreturn 1fisleep 2 && echo -n "."timeout=$((timeout+2))doneecho_successechoelseecho_failureif [ ! -e /var/lock/subsys/$SQUID ]; thenRETVAL=0fiechofireturn $RETVAL}reload() {$SQUID $SQUID_OPTS -k reconfigure -f $SQUID_CONF}restart() {stopstart}condrestart() {[ -e /var/lock/subsys/squid ] && restart || :}rhstatus() {status $SQUID && $SQUID -k check -f $SQUID_CONF}case "$1" instart)start;;stop)stop;;reload|force-reload)reload;;restart)restart;;condrestart|try-restart)condrestart;;status)rhstatus;;probe)probe;;*)echo $"Usage: $0 {start|stop|status|reload|force-reload|restart|try-restart|probe}"exit 2esacexit $?