<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>UNIXy &#187; restart</title>
	<atom:link href="http://blog.unixy.net/tag/restart/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.unixy.net</link>
	<description>Fully Managed Dedicated Servers</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:37:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Quick &amp; dirty Varnish monitoring script</title>
		<link>http://blog.unixy.net/2010/05/dirty-varnish-monitoring-script/</link>
		<comments>http://blog.unixy.net/2010/05/dirty-varnish-monitoring-script/#comments</comments>
		<pubDate>Thu, 27 May 2010 04:56:25 +0000</pubDate>
		<dc:creator>UNIXy</dc:creator>
				<category><![CDATA[Break-Fix]]></category>
		<category><![CDATA[crash]]></category>
		<category><![CDATA[crontab]]></category>
		<category><![CDATA[monitor]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[varnish]]></category>

		<guid isPermaLink="false">http://blog.unixy.net/?p=311</guid>
		<description><![CDATA[Depending on which version of Varnish you have running, there is a chance the code is still experimental and the whole Varnish daemon is prone to a fatal crash. Here is a quick and dirty monitoring script for Varnish. It essentially runs as a crontab job and requests a PING response. Should it not receive [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F05%2Fdirty-varnish-monitoring-script%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fblog.unixy.net%2F2010%2F05%2Fdirty-varnish-monitoring-script%2F&amp;style=normal&amp;b=2" height="61" width="50" /><br />
			</a>
		</div>
<p>Depending on which version of Varnish you have running, there is a chance the code is still experimental and the whole Varnish daemon is prone to a fatal crash.</p>
<p>Here is a quick and dirty monitoring script for Varnish. It essentially runs as a crontab job and requests a PING response. Should it not receive a PONG from Varnish, it will attempt a restart. There is a second round of testing within the same script. This is a second level of PING request; just in case. Be sure to set the usual defaults like -T port and varnish runlevel script.</p>
<blockquote><p><code>#!/bin/bash</code></p>
<p><code>result=$(echo -e "ping\n\r" | nc localhost 6082|grep PONG|wc -l);</code></p>
<p><code>if [ "${result}" -lt "1" ];<br />
then<br />
/etc/init.d/varnish stop;<br />
sleep 5;<br />
/etc/init.d/varnish start;<br />
echo "$(hostname): Varnish restart" | mail -s "$(hostname): Restarting varnish" alerts@example.com;<br />
fi</code></p>
<p><code>sleep 5;</code></p>
<p><code>results=$(echo -e "ping\n\r" | nc localhost 6082|grep PONG|wc -l);</code></p>
<p><code>if [ "${results}" -lt "1" ];<br />
then<br />
/etc/init.d/varnish stop;<br />
sleep 5;<br />
/etc/init.d/varnish start;<br />
echo "$(hostname): Second Varnish restart" | mail -s "$(hostname): Restarting varnish second time" alerts@example.com;<br />
fi</code></p>
<p><code> </code></p>
<p><code>exit 0;</code></p></blockquote>
<p>Finally load the job into crontab:</p>
<blockquote><p><code>*/5 * * * * /root/varnish.sh</code></p></blockquote>
<p>A cleaner way of accomplishing the same goal would be to establish a permanent connection to the Varnish admin port (6082 in this case) and issue a PING command every other second or so. The interval can be in the sub seconds as opposed to minutes as is the case with crontab.</p>
<p>Here is an example:</p>
<blockquote><p><code># telnet localhost 6082<br />
Trying 127.0.0.1...<br />
Connected to localhost.<br />
Escape character is '^]'.<br />
ping<br />
200 19<br />
PONG 1274931430 1.0<br />
ping<br />
200 19<br />
PONG 1274931434 1.0<br />
ping<br />
200 19<br />
PONG 1274931437 1.0<br />
ping<br />
200 19<br />
PONG 1274931443 1.0</code></p></blockquote>
<p>We deploy Varnish and other tools on our clients&#8217; server to get the most performance out of hardware. Our clients are happy with the performance boost and we are happy of the end result. Please do <a title="UNIXY's Portal" href="https://www.unixy.net/" target="_blank">get in touch</a> if you have any question or comment</p>
<p>That&#8217;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.unixy.net/2010/05/dirty-varnish-monitoring-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

