Tip: TextDrive and Lighttpd
Here’s a tip if you’re running rails applications under lighttpd on TextDrive: don’t use static fcgi processes.
The static FCGI processes are the ones you get when you specify a bin-path
in your configuration, a la:
1 2 3 4 5 6 7 8 9 10 |
fastcgi.server = ( ".fcgi" => ( "localhost" => ( "min-procs" => 1, "max-procs" => 1, "bin-path" => "public/dispatch.fcgi", "bin-environment" => ( "RAILS_ENV" => "production" ) ) ) ) |
There are two problems with doing it this way:
- Lighttpd doesn’t always like the way the Rails’
reaper
process plays with its processes, so you sometimes need to restart lighttpd when deploying a new version of your application. - Restarting lighttpd becomes extremely expensive, because all of the fastcgi processes get started up. With a single application that’s not a big deal, but if you start running more than one, you begin hating life when you have to restart lighttpd.
So, the solution?
First, create a tmp
directory in your rails project.
Then, create a spawn
script that looks something like this:
1 2 3 4 5 6 7 8 9 |
APP=yourapp ROOT=/home/you/path/to/$APP TMP=$ROOT/tmp ENV=production RAILS_ENV=$ENV spawn-fcgi -f $ROOT/public/dispatch.fcgi \ -s $TMP/$APP-0.socket -P $TMP/$APP-0.pid RAILS_ENV=$ENV spawn-fcgi -f $ROOT/public/dispatch.fcgi \ -s $TMP/$APP-1.socket -P $TMP/$APP-1.pid</pre> |
Go ahead and run this script. (What this does is spawn your fcgi processes externally. In this case, it spawns two processes, each listening on a different unix domain socket.)
Finally, tweak your lighttpd configuration so that it references the externally spawned fastcgi processes, instead of spawning directly:
1 2 3 4 |
fastcgi.server = ( ".fcgi" => ( "localhost" => ( "socket" => "/home/you/path/to/APP/tmp/APP-0.socket" ), ( "socket" => "/home/you/path/to/APP/tmp/APP-1.socket" ))) |
(Be sure to replace the paths with the correct paths that were specified in the spawn
script.) Then, restart lighttpd. Lighttpd will balance requests between the sockets you specify, so you can specify as few or as many as you need. (The fewer you use, the happier the TextDrive staff will be.)
Now, you can use the Rails reaper
command with confidence to restart your application, and restarting lighttpd is a very light, very inexpensive affair because your fastcgi processes are managed independently. You can now tweak your lighttpd configuration without fear!
(Note, however, that a reboot of the machine hosting your account will require you to run the spawn scripts for your applications again… I’m sure there’s a handy solution for that floating around somewhere, but I don’t know it offhand.)
Reader Comments
11 Feb 2006
11 Feb 2006
11 Feb 2006
11 Feb 2006
12 Feb 2006
12 Feb 2006
13 Feb 2006
14 Feb 2006
14 Feb 2006
16 Feb 2006
21 Feb 2006
24 Feb 2006
1 Mar 2006
15 Jun 2006