Ruby Enterprise Edition - Mac OS X problem

Posted by marcin
on Saturday, July 26

Last weekend I decide to play a bit with Ruby Enterprise Edition to do some performance testing and especially memory footprint. The installation process of REE went as smooth as it could – personally I’m a big fun of the installers which guide user through the installation giving all the hints on the spot (well done guys!). After installation had finished I just couldn’t wait any longer to bind it with Phusion Passenger and see it in action. Also, as my mod_rails installation got a bit old (1.0.5) I decided to update it to the newest available version (currently 2.0.2). NOTE: if you upgrade from mod_rails 1.0.5 to 2.0.2 you need to change your Apache configuration file:

- RailsRuby directive is now called PassengerRuby

- RailsSpawnServer is now obsolete and you should use PassengerRoot instead.

I changed my httpd.conf file accordingly:

PREVIOUS CONFIGURATION FOR PASSENGER 1.0.5 AND REGULAR RUBY 1.8.6

#LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so
#RailsSpawnServer /Library/Ruby/Gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server
#RailsRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby

NEW CONFIGURATION FOR PASSENGER 2.0.2 AND RUBY ENTERPRISE EDITION

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.0.2/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.0.2
PassengerRuby /private/opt/ruby-enterprise-1.8.6-20080709/bin/ruby

Note that PassengerRuby path leads to the Ruby Enterprise Edition installation folder.

After configuration change all you need to do is to restart your Apache, launch your application and benefit from lower memory footprint. In the end I was quite disappointed when I saw this error messages in Apache’s error_log file:

[Sat Jul 26 19:33:22 2008] [notice] Apache/2.2.6 (Unix) DAV/2 PHP/5.2.5 Phusion_Passenger/2.0.2 configured -- resuming normal operations
/Library/Ruby/Gems/1.8/gems/passenger-2.0.2/ext/passenger/native_support.bundle: [BUG] Bus Error
ruby 1.8.6 (2008-03-03) [i686-darwin9.2.2]

[Sat Jul 26 19:33:52 2008] [error] [client ::1] *** Unexpected error in Passenger: Cannot spawn application '/Users/xyz/Sites/my_rails_app': The spawn server has exited unexpectedly.

I’m not sure if this is problem specific to Mac OS X but noticed a few similar issues reported on the internet. Hoping that issue will be fixed very soon. Once it happens I’m going to give it another go and follow with some updates. Stay tuned!

Phusion Passenger a.k.a mod_rails

Posted by marcin
on Saturday, May 24

As deployment of even very simple web Rails apps was usually a pain (well, most of the cases) I decided to give mod_rails a go. The installation was a breeze as mod_rails installer guides you through the process nicely. Installation itself is as easy as that :

gem install passenger

Once your gem is installed run the following command (as root, otherwise you will get some “permission denied” errors)

passenger-install-apache2-module

Important note: In order to make Apache use your new shiny mod_rails you need to specifically modify its configuration by adding the following lines to your httpd.conf (NOTE: please change the paths accordingly!)

LoadModule passenger_module /Path/To/Gems/1.8/gems/passenger-1.0.5/ext/apache2/mod_passenger.so
RailsSpawnServer /Path/To/Gems/1.8/gems/passenger-1.0.5/bin/passenger-spawn-server
RailsRuby /Path/To/bin/ruby

After that all you need to do to make your app working is to modify / create virtual host definition:

<VirtualHost *:80>
      ServerName www.yourhost.com
      DocumentRoot /path/to/your/rails_app/public
</VirtualHost>

Now you are good to go ahead and restart your apache.

apachectl configtest
apachectl restart

For the test purposes I created a fresh rails app and start apache to serve it. The default page popped in on the screen which I took as a good sign ;) Next, I had created a simple controller with one action in it and then tried to reload the browser. The changes I made in the application weren’t reflected in the browser (the old version of the app was still in memory). Like in the case of standard setup (Webrick/Mongrel/etc.) with mod_rails you need to restart the application server in order for changes to take effect. One interesting thing here is that there is no command to be invoked from the command line to do it. Instead one need to create restart.txt file in application’s /tmp folder and then reload web browser pointing to your application.

touch /path/to/your/rails_app/tmp/restart.txt

Passenger loads your application into memory and keeps it there until one of the following events occur:

1. restart.txt has been created in application’s /tmp folder and web browser point to your app has been refreshed

2. Application has been idle for some time (the default it 120sec.) [see snippet below…]
[27:Application.h:264] Application 0x1a2ceb0: created.
[27:StandardApplicationPool.h:249] Cleaning idle app /path_to_your_app (PID 31918)
[27:Application.h:274] Application 0x1a2ceb0: destroyed.

If you have any issues with your deployment resulting in your app not being served / throwing errors go ahead and analyze your apache error_log (usually /var/log/apache2/error_log) and your application’s production log. It will give you some clues where things went wrong.

Also, mod_rails comes with pretty good documentation which can be found here.

Google I/O, San Francisco

Posted by marcin
on Thursday, May 01

It’s stating the obvious that the company I’m working for is the coolest company in the world :) From time to time I’m being sent over to the various conferences like Future Of the Web Apps, dConstruct, RailsConf, etc… This time I got lucky and am going to San Francisco to take part in Google I/O. The agenda looks really good! Am especially interested in GoogleAppEngine, the new cool way of deploying your web apps using Google’s super fast and scalable infrastructure, for free! GoogleGears, APIs, OpenSocial and other sessions seem to be very promising, too. Can’t wait… Will follow up with the conference review when I’m there…

Ruby unit testing frameworks

Posted by marcin
on Wednesday, April 30

Although I’m still pretty new in the Ruby world I’ve had chance and opportunity to work with people I could learn a lot from… Today I’ve spent some time with Jay Fields talking about testing frameworks for Ruby. I was truly amazed by the stuff he showed to me, namely dust and expectations lightweight unit testing frameworks. The latter has eventually surpassed the “dust”, however, in my opinion it’s good to have plenty of options to choose from. Personally I’m going to give a go to both of them in a project am working on currently. I’m looking to post some updates soon.

Getting Mephisto 0.8 up and running

Posted by marcin
on Thursday, April 17

I’ve spent some time recently trying to set up my brand new mephisto blog engine. Although mephisto is recognized as rather solid piece of software, sometimes you may face some issues. In my case I found the following error message in my production log :

LoadError (Expected /home/xyz/mephisto/app/models/asset.rb to define Asset):

In order to solve that issue follow these steps1 :

1. Find a place for ruby_inline to store its stuff, for example: RAILS_ROOT/tmp.

mkdir tmp/.ruby_inline
chown nobody:nobody tmp/.ruby_inline
chmod 755 tmp/.ruby_inline

2. Tell ruby_inline what you did by adding the following line in config/environment.rb:

ENV[‘INLINEDIR’] = File.join(File.dirname(FILE),”../tmp”)

3. Restart the server.

1 solution has been found at this blog