Arkanis Development

Styles

Rails FCGID dispatcher finder

Published

Another English post because this might come in handy for some people out there. Some Rails programmers out there may know the problem:

When updating your production server you've just run svn update to update the source of your Rails application. Because of cached code it is also necessary to restart the dispatchers of the Rails application.

Well, I have to admit, until now I simply restarted the Apache2 webserver or killed all dispatcher processes (killall dispatch.fcgi). However since there are quite a few Rails apps running on my server this always killed the other dispatchers, too. This isn't really a problem but more of "unnecessary brute force". The perfect solution would be to find the exact dispatcher of the Rails application I want to update and just kill this one.

But how? ps -A | grep dispatch.fcgi only prints out the PIDs of the dispatchers but not the paths. To work around this and I created a little script: find_dispatcher.rb.

It analyses the Apache log file and shows the data of every log entry where an FCGID dispatcher was started.

ruby find_dispatcher.rb

1722    Fri Jul 06 18:59:01 2007  /path/to/project/a/public/dispatch.fcgi
1755    Fri Jul 06 19:11:52 2007  /path/to/project/b/public/dispatch.fcgi
4615    Sat Jul 07 14:49:14 2007  /path/to/project/c/public/dispatch.fcgi
4931    Sat Jul 07 16:20:30 2007  /path/to/project/d/public/dispatch.fcgi

It's possible to specify a filter to just see the dispatchers created for a single project:

ruby find_dispatcher.rb -f project/b

1755    Fri Jul 06 19:11:52 2007  /path/to/project/b/public/dispatch.fcgi

To combine this script with others the --only-last-pid (or -p) option just prints out the last PID:

ruby find_dispatcher.rb -f project/b -p

1755

By default the script searches the /var/log/apache2/error.log file for matching entries. You can specify your own log file with the --log (-l for short) option.

ruby find_dispatcher.rb --log /my/own/log/file.log

This is it. --help will show an overview of all options. You can get the script directly out of my SubVersion repository: find_dispatcher.rb. Much fun with it.

Leave a new comment

Having thoughts on your mind about this stuff here? Want to tell me and the rest of the world your opinion? Write and post it right here. Be sure to check out the format help (focus the large text field) and give the preview button a try.

optional

Format help

Please us the following stuff to spice up your comment.

An empty line starts a new paragraph. ---- print "---- lines start/end code" ---- * List items start with a * or -

Just to keep your skill sharp and my comments clean.

or