Tip: TextDrive and Lighttpd
Posted by Jamis on February 11, 2006 @ 03:21 PM
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’
reaperprocess 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.)

1. Phil Ross said...
2. Gerry said...
3. Jamis said...
4. Michael Koziarski said...
5. rick said...
6. Jamis said...
7. Roeland said...
8. rick said...
9. Roeland said...
10. Traden said...
11. rick said...
12. jdh said...
13. rohit said...
14. Andrew said...