<?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>GeneralException &#187; Ruby</title>
	<atom:link href="http://www.generalexception.com/category/ruby/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.generalexception.com</link>
	<description>Family, work and life in general.</description>
	<lastBuildDate>Mon, 10 May 2010 05:38:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>On GOD and MONIT</title>
		<link>http://www.generalexception.com/2009/08/25/on-god-and-monit/</link>
		<comments>http://www.generalexception.com/2009/08/25/on-god-and-monit/#comments</comments>
		<pubDate>Tue, 25 Aug 2009 17:04:01 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Systems Architecture]]></category>

		<guid isPermaLink="false">http://www.generalexception.com/?p=13</guid>
		<description><![CDATA[When I recently resurrected this blog from after an untimely demise, I found it interesting to see how many people still get here from Google by querying for God.  When I first wrote that article, I had been planning to launch a little app for home brewers that I was writing in my spare time.  [...]]]></description>
			<content:encoded><![CDATA[<p>When I recently resurrected this blog from after an untimely demise, I found it interesting to see how many people still get here from Google by querying for <a href="http://god.rubyforge.org/">God</a>.  When I first wrote that article, I had been planning to launch a little app for home brewers that I was writing in my spare time.  I still have the project around and I do plan to launch it at some point, but its not on my short list of things to-do with my ever dwindling spare time (I have twin babies due in seven weeks).</p>
<p>Since then, I&#8217;ve started a new job with Agora Games as CTO, and our (good natured, ninja, rockstar) systems administrator <a href="http://lonelypinkelephants.com/">Jason LaPorte</a> sold me on <a href="http://mmonit.com/monit/">Monit</a>.  Why would a guy who gets most of his blog traffic (read: all 10 of you) based on a Google referral for GOD use Monit?   I think there&#8217;s a few reasons.</p>
<ol>
<li> <em>Stability</em> &#8211; Monit is very very stable.  It follows my favorite Unix design philosophy and does a very limited set of  things,very, very well.</li>
<li><em>Simplicity</em> &#8211; Monit configs are really easy to write, even for someone who isn&#8217;t a Unix Ninja.  Yes reader, even YOU can set up and configure Monit.  Likely in under a few minutes!</li>
<li><em>Overlord</em> &#8211; Using Monit and a few simple bash scripts Jason pieced together a really simple systems management application in Rails.  Its not for everyone, but it works really well for us.</li>
</ol>
<p>God is good.  God is great.  But, when you architect web applications for a living, eventually you realize that however great Ruby is (and Ruby as a language is truly awesome), having one less MRI process running, eating up RAM on your servers is really nice.  Its even nicer when your using a virtual hosting solution and you&#8217;re paying a premium for memory.  At this point, until we have a better Ruby interpreter my money (and our business) runs on  Monit.  YMMV.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalexception.com/2009/08/25/on-god-and-monit/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>God &#8211; Ruby Process Monitoring</title>
		<link>http://www.generalexception.com/2008/01/03/god-ruby-process-monitoring/</link>
		<comments>http://www.generalexception.com/2008/01/03/god-ruby-process-monitoring/#comments</comments>
		<pubDate>Thu, 03 Jan 2008 21:19:38 +0000</pubDate>
		<dc:creator>brian</dc:creator>
				<category><![CDATA[Ruby]]></category>

		<guid isPermaLink="false">http://www.generalexception.com/2008/01/03/god-ruby-process-monitoring/</guid>
		<description><![CDATA[I’ve been playing a lot lately with God, a process monitoring tool written in Ruby by Tom Preston-Werner.  If you run your app on either a VPS (I use Slicehost) or on a dedicated host, a monitoring tool is a must have for several reasons.
First, and most importantly, you can use it to keep [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve been playing a lot lately with <a href="http://god.rubyforge.com">God</a>, a process monitoring tool written in Ruby by <a href="http://rubyisawesome.com/">Tom Preston-Werner</a>.  If you run your app on either a VPS (I use <a href="http://www.slicehost.com">Slicehost</a>) or on a dedicated host, a monitoring tool is a must have for several reasons.</p>
<p>First, and most importantly, you can use it to keep an eye on your application.  When things go awry (as they always do) you can have god do things like alert administrators, restart processes, and anything else you can write a script to do.</p>
<p>Second, you can also use god as a general process control tool.  Often times you have application specific processes you want to run when the server starts up.  When you have only one application per server it might make some sense to handle this with shell scripts in init.d.  However, many us have multiple apps on the same server.  In this environment using init.d for application specific startup scripts means letting application specific tasks leak out of the application folder and mix with the main server configuration. So, rather than creating bash scripts to handle this you can let God do it and keep these scripts where they really belong; with the application.</p>
<p>That said, here&#8217;s my setup..</p>
<p><span id="more-4"></span></p>
<p>I have God installed on the server and configured to run on startup using a bash script. My main <em>god.conf</em> configuration file has an entry in it for each application which calls the applications specific <em>god\boot.rb</em> file local to each of my applications. This file loads all of the files in the god\initializers folder which is where I store my bits of god configurations.</p>
<p>This set up is not perfect, but its pretty nice. I can add new applications to my VPS and configure them to work with god by adding one line to my god.conf file and restarting the service. If I really want to get tricky, I can make a Capistrano task that restarts god on each deployment. Nice!</p>
<p>For each application, I can split my god config into parts, allowing me to manage different monitored pieces independantly.  For instance, on one application I&#8217;m watching Ferret (I know, I know), BackgroundDrb and Mongrel instances with configurations for each process in a separate file.</p>
<p>This setup favors one global god process which for me is handy because my VPS is low on memory. This has some tradeoffs like the fact that I only have one log file for all of my applications.  However, for my use the memory is worth more than the time it takes to glance through a long log.</p>
<p>Here’s what I did:</p>
<h2>Install the gem</h2>
<pre lang="bash">sudo gem install god
</pre>
<h2>Init Script</h2>
<p>Let’s go ahead and create the script:</p>
<pre lang="bash">sudo nano /etc/init.d/god
</pre>
<p>Inside the blank file place the following:</p>
<pre lang="bash">RETVAL=0

case "$1" in
    start)
      /usr/bin/god -P /var/run/god.pid -l /var/log/god.log
      /usr/bin/god load /etc/god.conf
      RETVAL=$?
  ;;
    stop)
      kill `cat /var/run/god.pid`
      RETVAL=$?
  ;;
    restart)
      kill `cat /var/run/god.pid`
      /usr/bin/god -P /var/run/god.pid -l /var/log/god.log
      /usr/bin/god load /etc/god.conf
      RETVAL=$?
  ;;
    status)
      RETVAL=$?
  ;;
    *)
      echo "Usage: god {start|stop|restart|status}"
      exit 1
  ;;
esac      

exit $RETVAL
</pre>
<h2>Execute</h2>
<p>As the init file is a shell script, it needs to have executable permissions.</p>
<p>We set them like so:</p>
<pre lang="bash">sudo chmod +x /etc/init.d/god
</pre>
<h2>update-rc</h2>
<p>Now we have the base script prepared, we need to add it to the default run levels:</p>
<pre lang="bash">sudo /usr/sbin/update-rc.d -f god defaults
</pre>
<p>The output will be similar to this:</p>
<p>Adding system startup for /etc/init.d/god …</p>
<pre lang="bash">/etc/rc0.d/K20god -&gt; ../init.d/god
/etc/rc1.d/K20god -&gt; ../init.d/god
/etc/rc6.d/K20god -&gt; ../init.d/god
/etc/rc2.d/S20god -&gt; ../init.d/god
/etc/rc3.d/S20god -&gt; ../init.d/god
/etc/rc4.d/S20god -&gt; ../init.d/god
/etc/rc5.d/S20god -&gt; ../init.d/god
</pre>
<h2>Application Specific Config</h2>
<p>Inside the root of your application, make a god folder and inside that folder, create another folder called initializers. Here’s what mine looks like:</p>
<pre lang="bash">$ ls god -r
god:
  initializers
</pre>
<p>In the god folder, create boot.rb:</p>
<pre lang="bash">sudo nano boot.rb
</pre>
<p>Inside the blank file place the following:</p>
<pre lang="ruby"># Do any global application config here, like setting up SMTP notifiers
God::Contacts::Email.message_settings = {:from =&gt; ‘god@myspiffyapp.com’}
God.contact(:email) do |c|
	c.name = ‘Admin’ c.email = ‘admincellphone@whatever.com’
end

# Borrowed this from the rails source, although God.load does take wildcards
Dir[”#{File.dirname(__FILE__)}/initializers/**/*.rb”].sort.each do |f|
load(f)
end
</pre>
<h2>Global config</h2>
<p>Next, we’re going to create a global god config file. In essence, its just going to load all of our application specific god files. To start, create a god.conf file:</p>
<pre lang="bash">sudo nano /etc/god.conf
</pre>
<p>Inside the blank file place the following:</p>
<pre lang="ruby"># Put an extra entry for each rails application that loads
# files from the god directory in each app.
boot_files = [”/apps/myapplication/current/god/boot.rb”]

boot_files.each do |f|
if File.exists?(f)
  load(RAILS_ROOT + '/god/boot.rb')
else
  p 'Can''t find config file in application directory!'
end
end
</pre>
<p>Make sure you change [”/apps/myapplication/current/god/boot.rb”] to the location of your application specific god boot file.<br />
Now save the file.</p>
<h2>Start, Stop and Restart</h2>
<p>Now we can start, stop and restart god just as with any other service:</p>
<pre lang="bash">sudo /etc/init.d/god start
sudo /etc/init.d/god stop
sudo /etc/init.d/god restart
</pre>
<p>The script will also be called on a reboot so god will automatically start.<br />
NOTE: If you have improperly written god config files, God won’t start. So, test these in advance of deployment and keep an eye on the /var/log/god log files.</p>
<h2>Summary</h2>
<p>In this article we installed the God monitoring tool, configured it to run on startup, and configured it to to load application specific config files for each of our applications.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.generalexception.com/2008/01/03/god-ruby-process-monitoring/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

