Ubuntu – Squid randomly stops serving requests. How to resolve this issue

PROXYsquidUbuntu

The squid (2.7) proxy that I have running on ubuntu 8.10 stops accepting new requests after being online for a while, due to reasons that I can't discover. However doing a squid -k reconfigure resolves the problem immediately.

Now I manually run this command by monitoring the log and if i don't see any activity for 5 minutes I reload the config.

Now on my quest for a solution I had several ideas:

  1. diagnose the root cause and eliminate it
  2. setup a script to automatically reload script if no new entries in access.log for the past 3 minutes
  3. painstakingly upgrade server to newer ubuntu version while keeping network offline or during off hours to minimize downtime.

I turn to you for solutions to option 2), as I do not understand squid enough for 1), and I'm avoiding 3) as long as i can. Any ideas?

Best Answer

I've come across a similar behaviour in squid (this was about 5 years ago - never got to the bottom of it) but in my case it would start slowing down after being up for 2-3 days.

Something like this run from cron should give the required behaviour for it locking up completely (assuming it stops writing to the log files):

 #!/bin/bash

 LOGFILE=/var/log/cache.log
 # you may need to change the above to point to your logfile
 LASTRUN=/var/local/squidcheck
 # above can be whatever - but dir must exist

 if [ ! -f ${LASTRUN} ] ; then
      touch ${LASTRUN}
 fi
 if [ ${LASTRUN} -nt ${LOGFILE} ] ; then
       /usr/sbin/squid -k reload
 fi
 touch ${LASTRUN}

This needs to run as root - so either in the root crontab, or the system crontab...

 */5 * * * * /path/to/shellscript

(note you should not edit the crontab file in place - use crontab -l >copy_ctb to get a copy of the current crontab, edit it, then load the new config using crontab copy_ctb)