Saturday, September 15, 2007

Easily display svn revision

In one of my projects we'll occasionally have production servers that don't get restarted on a deploy and this is a nightmare when it comes to tracking down bugs. Following the easy svn info parsing with YAML, we create a constant that holds our revision that gets set only when the server is starting.

Put this in your environment.rb:

Revision = YAML::load(`svn info $RAILS_ROOT`)["Revision"]

We can then easily display it along with other debug information to certain user accounts.

Note: since this is set in environment.rb it will only be set once at application startup. This is great for performance but will show stale revision information in development mode. This should be a non-issue for everyone since this exists solely for debugging production server failed restarts.