8

On my ubuntu machine, I have squid3 as a daemon which starts at boot.

The problem is that squid3 takes a long time to start and stop (more than 30 seconds) and it has also slowed down my OS startup/shutdown time considerably.

How can I solve this issue?

nixnotwin
  • 5,083

2 Answers2

17

There is a parameter called shutdown_lifetime. It has a default value of 30 seconds.

So when Squid receives a shutdown request, it waits at least 30 seconds before it terminates.

$ grep -B 8 "# shutdown_lifetime" /etc/squid3/squid.conf 

#  TAG: shutdown_lifetime   time-units
#   When SIGTERM or SIGHUP is received, the cache is put into
#   "shutdown pending" mode until all active sockets are closed.
#   This value is the lifetime to set for all open descriptors
#   during shutdown mode.  Any active clients after this many
#   seconds will receive a 'timeout' message.
# Default:
# shutdown_lifetime 30 seconds

Just "uncomment" the last line and set a shorter time:

shutdown_lifetime 10 seconds 

For more info see below.

http://www.squid-cache.org/Doc/config/shutdown_lifetime/

0

I found this for Squid 3.1.20-2.2 package for Debian Wheezy.

 $ vim /etc/init.d/squid3
 ...
 78
 79 stop () {
 80         PID=`cat $PIDFILE 2>/dev/null`
 81         start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON
 82         #
 83         #       Now we have to wait until squid has _really_ stopped.
 84         #
 85         sleep 2
 86         if test -n "$PID" && kill -0 $PID 2>/dev/null
 87         then
 88                 log_action_begin_msg " Waiting"
 89                 cnt=0
 90                 while kill -0 $PID 2>/dev/null
 91                 do
 92                         cnt=`expr $cnt + 1`
 93                         if [ $cnt -gt 24 ]
 94                         then
 95                                 log_action_end_msg 1
 96                                 return 1
 97                         fi
 98                         sleep 5
 99                         log_action_cont_msg ""
100                 done
101                 log_action_end_msg 0
102                 return 0
103         else
104                 return 0
105         fi
106 }
107...

, this function is using this unrecognized signal (0).


Workaround: at line 90, change the signal to a SIGTERM signal like, 15.

 90                 while kill -15 $PID 2>/dev/null


Then, there will be no delays when starting/stopping Squid:

$ time /etc/init.d/squid3 stop
[ ok ] Stopping Squid HTTP Proxy 3.x: squid3.

real    0m2.036s
user    0m0.004s
sys     0m0.000s

$  time /etc/init.d/squid3 start
[ ok ] Starting Squid HTTP Proxy 3.x: squid3.

real    0m0.036s
user    0m0.004s
sys     0m0.004s

Beware: although it provides fast start/stop for the service, this workaround could break the purpose of the script, which uses signal 0 for its own reasons.