Daily ArchiveWednesday, September 7th, 2005
Uncategorized 07 Sep 2005 08:21 am
Incomplete Guide to FastCGI
The Incomplete guide to using FastCGI at DreamHost.
(Some or all of this may pertain equally to other shared hosting environments also.)
It’s Incomplete in that I want to get the few lessons learned out quickly rather than working out the guide in great detail.
Eliminate 500 Server Errors
I’ve gotten rid of my Rails 500 errors. I haven’t seen one in weeks.
1) Download fcgi_handler.rb available in the rails svn:
http://dev.rubyonrails.org/svn/rails/trunk/railties/lib/fcgi_handler.rb
This is post-rails 0.13.1 (as yet unreleased), and you’ll need 0.13 or newer to use it. Specifically, your dispatch.fcgi should include only these lines (uncommented at least):
require File.dirname(__FILE__) + "/../config/environment"
require 'fcgi_handler'
RailsFCGIHandler.process!
2) Copy fcgi_handler.rb to your lib directory.
3) There is no step three!
You may see quite a few dispatch.fcgi processes, but they will exit gracefully instead of causing the 500 errors.
Restart your FastCGI Processes
There is the nice way and the effective way:
killall -USR1 dispatch.fcgi
killall -9 dispatch.fcgi
The first method will tell all processes to exit the next time they are called. I’ve found that they tend not to get cleaned up. (More on that later.) If you do this, even if you get a lot of processes running, you’ll find your app is happy and stable. DreamHost has a process sweeper that should clean up if you get too many processes.
The second will nuke them all even if a process is in mid-request. Mua ha ha. Before switching to the new fcgi_handler I did this each morning. Now I haven’t done it in a couple of weeks.
Eliminate Bugs in your App
This is really important. Even a ‘bug’ like not having a robots.txt file at your root can cause server errors, which can damage dispatch.fcgi processes, which then cause 500 errors (if you don’t use the fcgi_handler above).
Search your production.log and eliminate any issues, big or small.
Uncategorized 07 Sep 2005 07:14 am
Setting up a Debian development server
Some time ago I decided I’d really like to have an environment at home that mirrors a DreamHost server to enable me to do more testing and get a look under the covers at the various config options.
I also wanted to have a Trac install for clubrs.org.
I had a PIII with a 20GB drive and 512MB ram that I’d just retired from family use and it seemed a perfect candidate.
I really wanted 2 features in this server: security and ease of administration. The only machine I’ve had hacked was a Red Hat server and it was because I didn’t keep up with security releases. I want that to be as automatic as possible – I’m a developer, not a system admin.
I thought about going with FreeBSD since that seems to be popular with Rails developers and also is known as a secure OS. I also thought about Ubuntu for ease of use, but since DreamHost uses Debian I went that direction. So far at least, I’m very glad I did.
I’ll post a few articles covering the process: the trade-offs in OSes, the download/install process and setting up Trac.
The conclusion is that I’m very happy with Debian. In large part because it is a popular enough distribution that there are how-tos for everything and they seem to be very up to date. It installed easily and managing and updating packages is easy.
More to come….