Rails FCGID dispatcher finder

Vom 7. Juli 2007

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.

UPDATE: I just found out that ps -Af also prints the path to the processes. Together with grep it’s no deal to get the PID of a specific dispatcher (eg. ps -Af | grep collaboa). This makes the script a bit useless. However it can be still interesting to know when your dispatchers where started.

At least it was an exciting programming practice. :)

Abgelegt in: Programmieren, Projekte, Helion

Kommentar schreiben #leave_comment

(wird nicht veröffentlicht)

Es können Textilie- und einige Markdown-Codes verwendet werden. Bei Konflikten werden Textile-Codes bevorzugt.

Nur ein kleiner Anti-Spam-Test.

Projekte

Simple Localization
Ein einfaches, aber macht- volles Übersetzungsplugin für Ruby on Rails.
Table Navigation
Ein jQuery Plugin um per Tastatur schnell durch Tabellen zu navigieren.

Über was ich schreibe…

Newsfeeds

Kommentare