Ask Your Doctor About mod_rails
We need new inventions that reveal people’s true intentions, a portable pride protector, affordable lie detector…—Buck65
UPDATE: You can learn all about Phusion Passenger with the new PeepCode Screencast on the topic.
I was initially skeptical about mod_rails. The developers had the cojones to start promoting it weeks before it was ready, and they managed to generate a lot of hype around it before anyone had used it.
And we all know that hyped products never deliver!
Mostly, I was probably one of those developers described when they said
...we believe that experienced Ruby on Rails developers don’t consider deployment to be a problem; probably annoying at most…
Which is true. I was pretty happy with my current setup of Nginx and Mongrel. My only problem was that Nginx would often fail to create a pid file when the logs were rotated every night.
I still use Nginx and Mongrel at PeepCode, but I’ve switched a few smaller apps on a separate VPS to mod_rails. It turns out that there are many benefits to using mod_rails, both in development and production.
Great for development
It’s easy to ignore the pain of development. I didn’t realize how tedious it was to start and stop Mongrel while in development. It was also the reason I keep so many terminal tabs open at once.
With mod_rails, apps are always ready whenever I need them. If I need to watch the logs, it’s an easy tail -f log/development.log.
I have many pages that access dynamically generated graphs. A single Mongrel would process each serially, which would often take quite a while. With mod_rails, it’s nearly instant since new processes are spawned to handle the extra requests in parallel.
Configuration
I followed Manfred’s article to start using mod_rails in development. Two tweaks were to edit /etc/hosts and to point Apache to a local config file in my home directory.
First, edit /etc/hosts with fake names for the applications you’ll be developing against.
127.0.0.1 localhost peepcode.local podcast.localNext, in /etc/apache2/httpd.conf, I set the RailsEnv to development and myself to the RailsDefaultUser. I also included a config file in my home directory (stored in source control). This config file includes all my virtual hosts and is the same on both my laptop and my desktop machine.
RailsEnv development
RailsDefaultUser topfunky
Include /Users/topfunky/repos/configs/mod_rails_vhosts.confThe mod_rails_vhosts.conf file has several VirtualHost sections like this:
ServerName podcast.local
DocumentRoot /Users/topfunky/repos/podcast/publicEasy to debug visual plugins or graphs
Sometimes I need to visually debug code located in plugins or frozen gems. For example, I worked on some enhancements to my sparklines gem while viewing graphs on a reporting page. Normally, this would be impossible since Rails doesn’t reload itself for changes in the vendor directory.
Rstakeout comes to the rescue!
rstakeout "touch tmp/restart.txt" "vendor/**/*"
When I edit a plugin or gem in the vendor directory, mod_rails reloads the whole application and I can see the result immediately.
Rotate Logs
Other production tasks become very easy with mod_rails. Rotating the Rails logs is as easy as touching the restart.txt file.
Here’s /etc/logrotate.d/rails:
/var/www/apps/rubyonrailsworkshops.com/shared/log/production.log {
daily
rotate 7
compress
missingok
sharedscripts
postrotate
touch /var/www/apps/rubyonrailsworkshops.com/current/tmp/restart.txt
endscript
}Coexist
Many people are sad that mod_rails doesn’t yet support rack. No problem. I just followed Coda Hale’s classic article and am running Merb under Mongrel through Apache, alongside a few mod_rails apps.
Problems
The only initial problem I’ve experienced is that Apache seems to use much more memory than Nginx did. A few days after switching to Apache, the memory usage skyrocketed and killed all my mod_rails apps. I had to restart Apache to get everything back.
I’m working on a god config file to keep tabs on everything. Does anyone have a good one yet?
At PeepCode
Scott Chacon recently published a Git Internals PDF that Jamis Buck called required reading for all Git users. He also launched GitCasts.
Mike Mondragon and Luke Francl finished a book on MMS2R. If you’ve ever tried to receive email into a web application, you know it can be quite a pain. MMS2R is a gem that makes it super simple to receive both plain text and multimedia attachments. It’s made me want to write an email-powered application just so I can use the concepts they show in the book!
PeepCode Screencasts – Learn Ruby on Rails and Javascript! Hour-long screencasts for $9.
- Person:
- Programming Language:


Recent comments
1 year 23 weeks ago
1 year 23 weeks ago
1 year 25 weeks ago
1 year 27 weeks ago
1 year 42 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 45 weeks ago
1 year 46 weeks ago
1 year 48 weeks ago