Hi Jennings, You could avoid the race by also checking the elapsed seconds since varnish_uptime file was last written > new_varnish_uptime:
if [ $(($(date "+%s")-$(stat --printf="%Z" varnish_uptime))) -gt $new_varnish_uptime ]; then Note: completely untested code. And you can do integer arithmetic in bash without spawning bc with $(( )) El Fri Jan 23 2015 at 18:39:48, Jennings III, Raymond (< [email protected]>) escribió: > I was having a lot of segmenation faults in Varnish (due to our own > mistakes) but unless you are monitoring syslog or /var/log/kern you might > not ever know it's happening given that the child process restarts very > quickly so I wrote this little cron job: > > > You first have to bootstrap this right after you first install and start > varnish with: > > /usr/bin/varnishstat -1 | /bin/grep 'uptime' | /bin/awk '{ print $2}' > >/var/nyt/logs/varnish/varnish_uptime > > > > > The cron job is: > > > #!/bin/bash > > new_varnish_uptime=`/usr/bin/varnishstat -1 | /bin/grep 'uptime' | > /bin/awk '{ print $2}'` > old_varnish_uptime=`cat /var/nyt/logs/varnish/varnish_uptime` > > delta_time=$(echo "$new_varnish_uptime - $old_varnish_uptime" | > /usr/bin/bc) > > if [[ $delta_time -lt 0 ]]; then > echo "Uh oh!!! Varnish was restarted. It's uptime is now > $new_varnish_uptime and it used to be $old_varnish_uptime." | /bin/mail -s > "Varnish Server Restarted!" "[email protected]" > fi > > echo $new_varnish_uptime >/var/nyt/logs/varnish/varnish_uptime > > > > There is a race condition if Varnish is restarting faster than the > frequency of the cron job running. > > Raymond Jennings III > *nytimes.com <http://nytimes.com/>* > *Office: 212.556.7786 <212-556-7786>* > > *iPhone: 914.330.5074 <914-330-5074>E-mail: [email protected] > <[email protected]>FaceTime: [email protected] > <[email protected]>* > _______________________________________________ > varnish-misc mailing list > [email protected] > https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
_______________________________________________ varnish-misc mailing list [email protected] https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc
