<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.3" -->
<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/"
	>

<channel>
	<title>blog.westarete.com</title>
	<link>http://blog.westarete.com</link>
	<description></description>
	<pubDate>Wed, 10 Sep 2008 14:07:17 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.3</generator>
	<language>en</language>
			<item>
		<title>Quick Look preview from the command line</title>
		<link>http://blog.westarete.com/2008/09/10/quick-look-preview-from-the-command-line/</link>
		<comments>http://blog.westarete.com/2008/09/10/quick-look-preview-from-the-command-line/#comments</comments>
		<pubDate>Wed, 10 Sep 2008 14:01:29 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
	<category>Mac</category>
		<guid isPermaLink="false">http://blog.westarete.com/2008/09/10/quick-look-preview-from-the-command-line/</guid>
		<description><![CDATA[(This post is only for Mac folks, and only the ones that spend time in the terminal at that. Everyone else can safely ignore this.)
As you may already know, you can open a file from the command line using the &#8220;open&#8221; command. The file will be opened using the default application for the file type. [...]]]></description>
			<content:encoded><![CDATA[<p>(This post is only for Mac folks, and only the ones that spend time in the terminal at that. Everyone else can safely ignore this.)</p>
<p>As you may already know, you can open a file from the command line using the &#8220;open&#8221; command. The file will be opened using the default application for the file type. For example, running &#8220;open spreadsheet.xls&#8221; will open that file in Numbers or Excel, and running &#8220;open&#8221; on a directory will open that directory in a new Finder window. Think of it as a double click from the command line.</p>
<p>However, while working in the terminal today, I found myself wanting to open a spreadsheet using Quick Look just to get a single value. There&#8217;s a command called &#8220;qlmanage&#8221; that allows you to open the Quick Look preview of a file using the -p option. To make it more convenient, I created a short executable shell script called &#8220;ql&#8221; and put it in a directory that&#8217;s in my $PATH:</p>
<pre><code>
#!/bin/sh

# Display the Quick Look preview for the given file.

if [ -z "$1" ] ; then
  echo "Usage: ql <filename>&#8221;
  exit 1
fi

exec qlmanage -p $1 2> /dev/null
</code></pre>
<p>Now I can preview a spreadsheet (or any file) from the command line using &#8220;ql spreadsheet.xls&#8221;. To close the preview, just hit Ctrl-C.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.westarete.com/2008/09/10/quick-look-preview-from-the-command-line/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Giving from the top</title>
		<link>http://blog.westarete.com/2008/08/01/giving-from-the-top/</link>
		<comments>http://blog.westarete.com/2008/08/01/giving-from-the-top/#comments</comments>
		<pubDate>Fri, 01 Aug 2008 19:37:12 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
	<category>Philanthropy</category>
		<guid isPermaLink="false">http://blog.westarete.com/2008/08/01/giving-from-the-top/</guid>
		<description><![CDATA[1% For The Planet is a group of companies that have pledged to donate 1% of their annual sales to nonprofit environmental organizations. By donating a fixed portion of their &#8220;top line&#8221;,  these companies are committed to giving through thick and thin.
They&#8217;ve just released a new promotional video that they&#8217;re showing during Jack Johnson&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://onepercentfortheplanet.org">1% For The Planet</a> is a group of companies that have pledged to donate 1% of their annual sales to nonprofit environmental organizations. By donating a fixed portion of their &#8220;top line&#8221;,  these companies are committed to giving through thick and thin.</p>
<p>They&#8217;ve just released a new promotional video that they&#8217;re showing during Jack Johnson&#8217;s world tour. I love Tyler Stableford&#8217;s photography, and the soundtrack is great too (Matt Costa):</p>
<p><object width="425" height="344"><br />
<param name="movie" value="http://www.youtube.com/v/98uXpfcRJzs&#038;fs=1"></param>
<param name="wmode" value="transparent"></param>
<param name="allowFullScreen" value="true"></param><embed src="http://www.youtube.com/v/98uXpfcRJzs&#038;fs=1" type="application/x-shockwave-flash" allowfullscreen="true" wmode="transparent" width="425" height="344"></embed></object></p>
<p>Since our first day in business, West Arete Computing has been proud to be a member of 1% For The Planet (we&#8217;re <a href="http://onepercentfortheplanet.org/en/search/member_profile_page.php?id=96">member #97</a>). It&#8217;s great knowing that every project that we&#8217;ve ever worked on has resulted in more funding for some of our favorite nonprofit environmental organizations.</p>
<p>It&#8217;s been a privilege knowing the people at 1% For The Planet for the past few years. You&#8217;ll never find a more driven, energetic, fascinating group of people. It&#8217;s been thrilling to watch how much the movement has taken off recently &#8212; there are more than <b>900 member companies</b> now.</p>
<p>Keep your eye out for the 1% For The Planet logo. I keep on finding it in places that I didn&#8217;t expect. It&#8217;s great to see it on things that you&#8217;ve been buying for years. </p>
<p>It&#8217;s also great to go to work each day knowing that part of that effort goes towards keeping central Pennsylvania beautiful.</p>
<p><img id="image11" width="81" height="120" src="http://blog.westarete.com/wp-content/uploads/2008/08/logo_vert_standard_color.gif" alt="1% For The Planet logo" style="display: block; margin-left: auto; margin-right: auto; margin-top: 2em;" /><br />
<div style="clear: both"></div>
]]></content:encoded>
			<wfw:commentRSS>http://blog.westarete.com/2008/08/01/giving-from-the-top/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Stratamodel in Niger</title>
		<link>http://blog.westarete.com/2008/02/16/stratamodel-in-niger/</link>
		<comments>http://blog.westarete.com/2008/02/16/stratamodel-in-niger/#comments</comments>
		<pubDate>Sat, 16 Feb 2008 16:34:06 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
	<category>Rails</category>
		<guid isPermaLink="false">http://blog.westarete.com/2008/02/16/stratamodel-in-niger/</guid>
		<description><![CDATA[Tom Bell of Stratamodel is an exploration geologist. He travels around the world looking for valuable minerals. He&#8217;s just wrapping up a several-week expedition to the desert in Niger to look for uranium. This guy has an incredible job.
Tom gave me a ring a few days before leaving for his trip to see if we [...]]]></description>
			<content:encoded><![CDATA[<p>Tom Bell of <a href="http://stratamodel.com">Stratamodel</a> is an exploration geologist. He travels around the world looking for valuable minerals. He&#8217;s just wrapping up a several-week expedition to the desert in Niger to look for uranium. This guy has an incredible job.</p>
<p>Tom gave me a ring a few days before leaving for his trip to see if we could put together a quick program for his laptop. He had a set of barometers/thermometers that connected to the USB port on his Windows laptop, and he wanted us to write some software to read the data from the devices and record it. He also wanted to ensure that it could all run unattended, and that it would maximize battery life. We also had to be 100% sure that the program would work properly, since he would hardly have any outside contact once he entered the desert.</p>
<p>Using the specifications from the manufacturer, we put together a Ruby program to talk to the devices and record the data (we used the ruby-serialport gem, if you&#8217;re wondering how). Getting the timing right with the devices was the only tricky part &#8212; they were very picky about how much time elapsed between sending and receiving each character, and between sending a command and retrieving the response.</p>
<p>To save power, we set up the code and data on a flash drive so it wouldn&#8217;t use the hard drive. We then set up a power scheme that would keep the computer running, but would shut down the hard drive, display, and allow the machine to keep running with the lid closed (essential for keeping out dust and sand). </p>
<p>All in all, we had everything developed, tested, and installed in about 24 hours. </p>
<p>After hearing about what his trip was going to entail, we also set up a blog for him to write about his experiences. He&#8217;s been writing some great stories and taking a lot of amazing pictures. I&#8217;m really struck by how similar some of the desert pictures are to the ones from the Mars rovers!</p>
<p>I highly recommend checking out the <a href="http://stratamodel.com/blog">Stratamodel blog</a>. Also be sure to check out the <a href="http://www.flickr.com/photos/stratamodel/">Stratamodel photo stream on flickr</a>. Great material. Have a great trip Tom!</p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.westarete.com/2008/02/16/stratamodel-in-niger/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Exploring Ruby class methods</title>
		<link>http://blog.westarete.com/2008/02/15/exploring-ruby-class-methods/</link>
		<comments>http://blog.westarete.com/2008/02/15/exploring-ruby-class-methods/#comments</comments>
		<pubDate>Fri, 15 Feb 2008 14:04:14 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
	<category>Rails</category>
		<guid isPermaLink="false">http://blog.westarete.com/2008/02/15/exploring-ruby-class-methods/</guid>
		<description><![CDATA[I decided that I needed to learn more about all the different ways to declare and use Ruby class methods, so I wrote a 10-line example script to try a couple things out. Two hours later, it had expanded to almost 300 lines (including lots of comments) as I tried to demonstrate and explain every [...]]]></description>
			<content:encoded><![CDATA[<p>I decided that I needed to learn more about all the different ways to declare and use Ruby class methods, so I wrote a 10-line example script to try a couple things out. Two hours later, it had expanded to almost 300 lines (including lots of comments) as I tried to demonstrate and explain every way that I could think of to declare and use class methods.</p>
<p><a href="http://pastie.caboo.se/152661">Take a look</a>, <a href="http://pastie.caboo.se/pastes/152661/download">download the code</a>, open it in your editor, and run it (Apple-R in TextMate). Mess around with it. </p>
<p>Did I miss anything? Did I get anything wrong? Post your comments and questions in the comments below. </p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.westarete.com/2008/02/15/exploring-ruby-class-methods/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Anti-specs: Using RSpec to document the bad in addition to the good</title>
		<link>http://blog.westarete.com/2007/12/13/anti-specs-using-rspec-to-document-the-bad-in-addition-to-the-good/</link>
		<comments>http://blog.westarete.com/2007/12/13/anti-specs-using-rspec-to-document-the-bad-in-addition-to-the-good/#comments</comments>
		<pubDate>Thu, 13 Dec 2007 21:51:50 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
	<category>Rails</category>
		<guid isPermaLink="false">http://blog.westarete.com/2007/12/13/anti-specs-using-rspec-to-document-the-bad-in-addition-to-the-good/</guid>
		<description><![CDATA[Sometimes we purposely write code that has bugs that we don&#8217;t intend to fix. 
I know that sounds terrible, but consider the following example. We were recently writing a class to parse a known set of data that didn&#8217;t include any whitespace between tokens. Our one-time class worked great for this particular data set, and [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we purposely write code that has bugs that we don&#8217;t intend to fix. </p>
<p>I know that sounds terrible, but consider the following example. We were recently writing a class to parse a known set of data that didn&#8217;t include any whitespace between tokens. Our one-time class worked great for this particular data set, and we didn&#8217;t anticipate having to use it on another data set. However, if you were to pass it similar data that did have whitespace between tokens, then you wouldn&#8217;t get the desired output. </p>
<p>We could have spent a bunch of time expanding the class to handle whitespace properly, but we quickly realized that this would have doubled the development time for the class, all for adding a feature that we weren&#8217;t going to use. </p>
<p>Instead, we added some anti-specs for the class that documented the undesirable behavior:</p>
<pre><code>
  describe "Unfortunately, #quote_nodes" do
    it "will preserve whitespace around each node" do
      quote_nodes(" snap , crackle ,( pop )").should == "' snap ',' crackle ',(' pop ')"
    end

    it "will quote whitespace as a node if it appears between delimiters" do
      quote_nodes(" , , ( ) ").should == "' ',' ',' '(' ')' '"
    end
  end
</pre>
<p></code></p>
<p>Note how instead of the usual RSpec phrasing, e.g. &#8220;#quote_nodes &#8230; should put single quotes around each node&#8221;, we start the context with &#8220;Unfortunately&#8221; to immediately tell the reader that this is undesirable behavior, and we use the word &#8220;will&#8221; instead of &#8220;should&#8221; to tell you that this isn&#8217;t what we would want in an ideal world, but it&#8217;s what we&#8217;re getting anyway. You wind up with spec docs that clearly document the good and the bad:</p>
<pre><code>
#quote_nodes:
- should put single quotes around each node
- should quote nested nodes too
- should only treat parentheses and commas as delimiters
- should preserve whitespace within nodes

Unfortunately, #quote_nodes:
- will preserve whitespace around each node
- will quote whitespace as a node if it's between delimiters
</pre>
<p></code></p>
<p>Down the road, we may wind up re-using this code in another application. If we need to fix the bad behavior, we can simply modify the specs to document the new desired behavior, and then add the additional code to properly handle whitespace and make the tests pass.</p>
<p>I didn&#8217;t see anyone else writing about this use of RSpec, but we&#8217;ve found it to be useful for these somewhat rare cases. </p>
<p>There&#8217;s no reason why you couldn&#8217;t do this with <a href="http://www.ruby-doc.org/stdlib/libdoc/test/unit/rdoc/">Test::Unit</a> and have &#8220;anti-tests&#8221;, but I particuarly like the phrasing that you get to use with a <a href="http://en.wikipedia.org/wiki/Behavior_driven_development">BDD</a> framework such as <a href="http://rspec.rubyforge.org/">RSpec</a> or <a href="http://thoughtbot.com/projects/shoulda">shoulda</a>.</p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.westarete.com/2007/12/13/anti-specs-using-rspec-to-document-the-bad-in-addition-to-the-good/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Copying a large amount of data between disks</title>
		<link>http://blog.westarete.com/2007/11/12/copying-a-large-amount-of-data-between-disks/</link>
		<comments>http://blog.westarete.com/2007/11/12/copying-a-large-amount-of-data-between-disks/#comments</comments>
		<pubDate>Mon, 12 Nov 2007 15:29:29 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
	<category>Rails</category>
		<guid isPermaLink="false">http://blog.westarete.com/2007/11/12/copying-a-large-amount-of-data-between-disks/</guid>
		<description><![CDATA[We upgraded the disks on our backup server to create some much-needed space. When the new drive arrived, I had to reformat it and copy the entire contents of the old backup disk to the new one. I needed a way to transfer 250GB of small files, while preserving permissions and hard links. I tried [...]]]></description>
			<content:encoded><![CDATA[<p>We upgraded the disks on our backup server to create some much-needed space. When the new drive arrived, I had to reformat it and copy the entire contents of the old backup disk to the new one. I needed a way to transfer 250GB of small files, while preserving permissions and hard links. I tried three different methods of copying the data before finally succeeding. </p>
<p>This is on a Xen virtual server and memory is somewhat limited (256MB). Both rsync and restore took *way* too much memory. Rsync would have required many gigabytes of memory, and restore required at least a couple. Restore also required a large amount of temporary disk space (a couple gigabytes) for storing permissions and mode information. In the end, the good old tar command was the highest-performance method, consuming about 150MB of memory at its peak for the restore. The bash command line was:</p>
<pre><code>
  (cd /data &#038;&#038; tar -c -p -f - .) | (cd /data2 &#038;&#038; tar -x -p -f -)
</code></pre>
<p>Tar is dependent on the current directory for its context, so I used a subshell around each command to ensure that they were in the right directory. I could have used semicolons to separate the &#8220;cd&#8221; command from the &#8220;tar&#8221; command in each subshell, but then the &#8220;tar&#8221; would have proceeded whether or not the &#8220;cd&#8221; was successful (for example if I had made a typo in the directory name). This would be bad since a failed &#8220;cd&#8221; before a tar restore could result in all of those files being written and potentially intermingled with the wrong filesystem. Using &#8220;&#038;&#038;&#8221; to separate the commands ensures that the tar command only proceeds if the &#8220;cd&#8221; was successful.
</p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.westarete.com/2007/11/12/copying-a-large-amount-of-data-between-disks/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>New rails plugin: validate_request</title>
		<link>http://blog.westarete.com/2006/07/26/new-rails-plugin-validate_request/</link>
		<comments>http://blog.westarete.com/2006/07/26/new-rails-plugin-validate_request/#comments</comments>
		<pubDate>Wed, 26 Jul 2006 22:46:03 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
	<category>Rails</category>
	<category>Ruby</category>
	<category>Security</category>
		<guid isPermaLink="false">http://blog.westarete.com/2006/07/26/new-rails-plugin-validate_request/</guid>
		<description><![CDATA[One thing that bothered me when I started using rails was that there wasn&#8217;t a built-in way to verify that your actions are getting the correct arguments. For example, in this typical action:

  def show
    @dog = Dog.find(params[:id])
  end

an exception is raised if the &#8220;id&#8221; parameter is omitted (e.g. /dog/show [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that bothered me when I started using rails was that there wasn&#8217;t a built-in way to verify that your actions are getting the correct arguments. For example, in this typical action:</p>
<pre><code>
  def show
    @dog = Dog.find(params[:id])
  end
</code></pre>
<p>an exception is raised if the &#8220;id&#8221; parameter is omitted (e.g. /dog/show rather than /dog/show/5), and you get a rails application error by default. It seemed like there should be a way to declare that this action requires an &#8220;id&#8221; parameter of type integer, and provide a graceful way to recover if that constraint isn&#8217;t met.</p>
<p><a id="more-4"></a></p>
<p>This was something that we had built into our in-house PHP framework long ago, and we had become quite accustomed to it. Such a feature essentially allows you to describe and enforce the interface to your controllers&#8217; actions.</p>
<p>It&#8217;s a good exercise to define the set of valid methods and parameters that can be used to call your actions, and it&#8217;s very handy to have notification and helpful logging messages for when your constraints aren&#8217;t met. It&#8217;s the same argument as the one that says that you should carefully consider the interface between your classes.</p>
<p>So I wrote a new plugin called <code>validate_request</code> to easily perform this type of checking, and recover gracefully (and configurably) if the constraints aren&#8217;t met. Now you can specify constraints like this:</p>
<pre><code>
  def show
    validate_request(:get, :id => :integer) or return
    @dog = Dog.find(params[:id])
  end
</code></pre>
<p>and perhaps more importantly like this:</p>
<pre><code>
  def update
    validate_request(:post, :id => :integer, :dog => Dog) or return
    @dog = Dog.find(params[:id])
    @dog.update_attributes(params[:dog])
    ...
  end
</code></pre>
<p>This way, your argument checking isn&#8217;t as tightly coupled to your database schema &#8212; attributes can be added and removed from the Dog model, and you won&#8217;t have to change your request validation code.</p>
<p>That&#8217;s a lot of benefit for only one line of code per action. </p>
<p>You can install the plugin by running the following commands from your rails application&#8217;s directory:</p>
<pre><code>
  ./script/plugin source svn://rubyforge.org//var/svn/validaterequest/plugins
  ./script/plugin install validate_request
</pre>
<p></code></p>
<p>Here are some other resources:</p>
<ul>
<li><a href="http://rubyforge.org/projects/validaterequest/">The RubyForge project page</a></li>
<li><a href="http://rubyforge.org/docman/view.php/1984/455/README.txt">The README file</a></li>
<li><a href="http://rubyforge.org/docman/view.php/1984/456/USAGE.txt">The USAGE file</a>, which gives more in-depth instructions on how to use validate_request in your code</li>
</ul>
<p>There are a few items that are on the to-do list, such as support for aspects in RESTful URLs, and what amounts to enumerated types. </p>
<p>Let me know how things work out for you.</p>
]]></content:encoded>
			<wfw:commentRSS>http://blog.westarete.com/2006/07/26/new-rails-plugin-validate_request/feed/</wfw:commentRSS>
		</item>
		<item>
		<title>Deploying Mongrel behind Apache 2.0</title>
		<link>http://blog.westarete.com/2006/07/25/deploying-mongrel-behind-apache-20/</link>
		<comments>http://blog.westarete.com/2006/07/25/deploying-mongrel-behind-apache-20/#comments</comments>
		<pubDate>Tue, 25 Jul 2006 17:14:13 +0000</pubDate>
		<dc:creator>scott</dc:creator>
		
	<category>Rails</category>
	<category>Ruby</category>
	<category>Deployment</category>
		<guid isPermaLink="false">http://blog.westarete.com/2006/07/25/deploying-mongrel-behind-apache-20/</guid>
		<description><![CDATA[Most of the documentation and writings for mongrel require setting up mongrel with apache 2.2, so that you get the benefit of the mod_balanced_proxy module. However there are an awful lot of production machines out there running apache 2.0.
For small installations, it turns out that it can be quite sufficient to run a single mongrel [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the documentation and writings for mongrel require setting up mongrel with apache 2.2, so that you get the benefit of the mod_balanced_proxy module. However there are an awful lot of production machines out there running apache 2.0.</p>
<p>For small installations, it turns out that it can be quite sufficient to run a single mongrel daemon behind Apache 2.0 and plain old mod_proxy, all on one machine. No, you won&#8217;t get high concurrency, and you won&#8217;t be able to load balance across machines, but it&#8217;s an incredibly simple, stable setup that can have your rails app up and running without mucking around with upgrading your web server or installing foreign RPMs.</p>
<p><a id="more-3"></a></p>
<p>Here are the prerequisites:</p>
<ul>
<li>You have apache 2.0 already installed and running.</li>
<li>If you&#8217;re on a shared host, you&#8217;ve been assigned a high-numbered port to use for mongrel to listen on (just file a support ticket requesting this).</li>
<li>You&#8217;ve followed one of the other tutorials online to verify that you can get a single mongrel instance running (even by hand) for your rails application on your high-numbered port on the same machine as the apache server.</li>
</ul>
<p>From here on out, let&#8217;s presume the following. Substitute appropriately in the examples:</p>
<ol>
<li>The website that you&#8217;re developing is example.com</li>
<li>Your high-numbered port is 4000</li>
</ol>
<p>Go ahead and start up mongrel in production mode on your server. If you&#8217;re doing it by hand, you&#8217;ll probably use a command like:</p>
<pre>
    $ cd /var/www/domains/example.com/current/
    $ mongrel_rails start -e production -p 4000
</pre>
<p>Now you should be able to visit http://example.com/4000, and see your rails application. If you get a rails application error, check your production rails log and the mongrel log to see what&#8217;s going wrong. Make sure you&#8217;ve set up your production database (and production stanza in database.yml) properly. You might also have trouble if the host in question has firewalled the high-numbered ports, and your browser is running on a different machine. In that case, you can use the command-line web client &#8220;curl&#8221; on the server itself to request the page:</p>
<pre>
    $ curl http://localhost:4000/
</pre>
<p>It should spit out the HTML of example.com&#8217;s home page. </p>
<p>Once you&#8217;re sure that mongrel is running properly on port 4000, we&#8217;re ready to use apache to proxy requests back to it, so that you can access the site without the port number.</p>
<p>If you&#8217;re using virtual hosts, this is the stanza that you can use in your httpd.conf file:</p>
<pre>
    &lt;VirtualHost *:80&gt;
        ServerName example.com
        ProxyPass / http://localhost:4000/
        ProxyPassReverse / http://localhost:4000/
    &lt;/VirtualHost&gt;
</pre>
<p>This simply tells apache that for requests that are destinted for example.com, proxy them to port 4000 on the localhost, which is where mongrel is running.</p>
<p>After checking and reloading your apache configuration, your site should now be available on http://example.com/</p>
<h6>Making It Stick</h6>
<p>The site&#8217;s running, but if the server reboots, mongrel may not be set up to restart automatically, so nothing will be serving your rails site. You&#8217;ll probably want to create a startup script that starts your mongrel servers on boot. My startup script contains a line like this for each site:</p>
<pre>
mongrel_rails start -e production -d -a 127.0.0.1 --user mongrel --group mongrel -p 4000 -c /var/www/domains/mydomain.com/current
</pre>
<p>Some things above are worth mentioning:</p>
<ul>
<li>It would be nicer to use a mongrel config file to store this information, rather than specifying it all on the command line. Unfortunately, I couldn&#8217;t seem to get the config files to work &#8212; mongrel would always ignore them. I eventually retreated to command-line options again.</li>
<li><code>-a 127.0.0.1</code> tells mongrel to only accept requests from localhost. We don&#8217;t need to allow outsiders to access port 4000.</li>
<li>(Extra credit) It&#8217;s a good idea to run your services under their own account for security reasons. Mongrel supports this via the &#8211;user and &#8211;group options. I created a &#8220;mongrel&#8221; user and group, and then make sure that that user can read but not write to the source files. You also can give the mongrel user ownership of the directories that it needs to write to (log and sessions), rather than making those directories world-writable.</li>
<li>The -c option tells mongrel which directory to &#8220;cd&#8221; to before it starts, so this points to the rails application directory.</li>
</ul>
]]></content:encoded>
			<wfw:commentRSS>http://blog.westarete.com/2006/07/25/deploying-mongrel-behind-apache-20/feed/</wfw:commentRSS>
		</item>
	</channel>
</rss>
