This TOTD explains the steps to setup a Mongrel cluster for JRuby-on-Rails applications on a Unix flavor operating system. These instructions do NOT work on Windows. A similar post for Windows is cooking and will be posted when ready.
-
Download JRuby 1.0.1 and unzip the bundle (say JRUBY_HOME).
-
For convenience, include
JRUBY_HOME/bin
to your PATH.
-
-
Install the required RubyGems
-
Install Rails as shown below:
jruby -S gem install rails --version 1.2.3 --include-dependencies --no-ri --no-rdoc
Bulk updating Gem source index for: http://gems.rubyforge.org
Successfully installed rails-1.2.3
Successfully installed activesupport-1.4.2
Successfully installed activerecord-1.15.3
Successfully installed actionpack-1.13.3
Successfully installed actionmailer-1.3.3
Successfully installed actionwebservice-1.2.3 -
Before installing Mongrel, install the pre-requisite Gems as shown below (see discussion here):
jruby -S gem install gem_plugin --no-ri --no-rdoc
Successfully installed gem_plugin-0.2.2and another one:
jruby -S gem install cgi_multipart_eof_fix --no-ri --no-rdoc
Successfully installed cgi_multipart_eof_fix-2.3 -
Mongrel cannot be installed as a gem on JRuby yet. So download Mongrel gem and install it as shown below:
jruby -S gem install mongrel-1.0.1-jruby.gem --no-ri --no-rdoc
Successfully installed mongrel, version 1.0.1Make sure to invoke the command from the directory where the gem is downloaded.
-
Install Mongrel cluster.
mongrel_cluster
does not work with JRuby and so insteadmongrel_jcluster
needs to be installed as shown below:jruby -S gem install mongrel_jcluster --include-dependencies --no-ri --no-rdoc
Successfully installed mongrel_jcluster-0.0.1As mentioned here,
mongrel_jcluster
is still quite experimental and not guaranteed to work in any way but it worked for this post
-
-
Create a template application say in JRUBY_HOME/samples as shown below:
/home/arung/testbed/jruby-1.0.1/samples/rails 1954 $ ../../bin/jruby -S rails hello
create
create app/controllers
create app/helpers
create app/models
...
create log/production.log
create log/development.log
create log/test.log -
Start Mongrel as shown below:
cd hello
/home/arung/testbed/jruby-1.0.1/samples/rails/hello $ ../../../bin/jruby script/server
=> Booting Mongrel (use 'script/server webrick' to force WEBrick)
=> Rails application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
** Ruby version is not up-to-date; loading cgi_multipart_eof_fix
** Starting Mongrel listening at 0.0.0.0:3000
** Starting Rails with development environment...
** Rails loaded.
** Loading any Rails specific GemPlugins
** Signals ready. TERM => stop. USR2 => restart. INT => stop (no restart).
** Rails signals registered. HUP => reload (without restart). It might not work well.
** Mongrel available at 0.0.0.0:3000
** Use CTRL-C to stop.The application is now available at
http://localhost:3000
. Hit Ctrl-C to stop Mongrel as shown below:^C** INT signal received.
Exiting
/home/arung/testbed/jruby-1.0.1/lib/ruby/gems/1.8/gems/activesupport-1.4.2/lib/active_support/dependencies.rb:498:in
`require': Mongrel::StopServer (Mongrel::StopServer)
from /home/arung/testbed/jruby-1.0.1/lib/ruby/gems/1.8/gems/rails-1.2.3/lib/commands/server.rb:39
from /home/arung/testbed/jruby-1.0.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from /home/arung/testbed/jruby-1.0.1/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`require'
from :1 -
Configure and Start Mongrel cluster
-
Configure Mongrel cluster as shown below:
/home/arung/testbed/jruby-1.0.1/samples/rails/hello $ ../../../bin/jruby -S mongrel_rails jcluster::configure -p 8000 -N 2
Writing configuration file to config/mongrel_cluster.yml.This starts a cluster of 2 Mongrels (identified by
-N 2
) assigning ports in the ascending order starting at 8000 (identified by-p 8000
). -
Start Mongrel cluster as shown below:
/home/arung/testbed/jruby-1.0.1/samples/rails/hello $ ../../../bin/jruby -S mongrel_rails jcluster::start
** Ruby version is not up-to-date; loading cgi_multipart_eof_fix
Starting JRuby server...
Starting 2 Mongrel servers...
-
-
Now your application is available on
http://localhost:8000
andhttp://localhost:8001
. All the logs (for all the instances) are available inlog/development.log
. -
The cluster can be stopped as shown below:
/home/arung/testbed/jruby-1.0.1/samples/rails/hello $ ../../../bin/jruby -S mongrel_rails jcluster::stop
** Ruby version is not up-to-date; loading cgi_multipart_eof_fix
Stopping 2 Mongrel servers...
A follow up post will show how to front-end this cluster of Mongrels with a light-weight HTTP server.
An alternative to this behemoth configuration is to create a Web ARchive (WAR) of your JRuby-on-Rails application and deploy on GlassFish. A complete screencast of how this can be achieved using NetBeans IDE is shown here. A comprehensive list of JRuby on GlassFish documentation is available here.
Technorati: totd rubyonrails jruby mongrel unix jrubyonglassfish glassfish netbeans ruby
Related posts:- TOTD #13: Setup Mongrel for JRuby-on-Rails applications on Windows
- TOTD #14: How to generate JRuby-on-Rails Controller on Windows (#9893)
- TOTD #24: Getting Started with Rails 2.0.x in JRuby 1.0.3 and JRuby 1.1RC1
- JRuby 1.0.3 + Rails 2.0 Hello World – Additional Steps Required
- TOTD #79: Getting Started with Sinatra applications on JRuby and GlassFish Gem
[Trackback] In a previous entry, I posted instructions on how to setup Mongrel cluster for JRuby-on-Rails applications on Unix-based systems. The instructions specified there do not work on Windows-based systems because of the following reasons: JRuby 1.0.1 + (def…
Comment by Arun Gupta's Blog — October 12, 2007 @ 9:38 am
Nice write-up! I think there’s a small error in item 5: you need the -S option when you run mongrel_rails with jruby.
Also, the server only starts on port 8000.
Comment by Kjetil — November 23, 2007 @ 4:27 am
Thanks for the catch, fixed the typo!
When the Cluster was configured, then I could see exact same page hosted at port 8000 and 8001. Can you explain your second comment ?
Comment by Arun Gupta — November 23, 2007 @ 5:36 am
I’ve followed above configurations for jruby mongrel_cluster but I’m getting the below error
jruby -S mongrel_rails jcluster::start
Starting JRuby server…
Starting 2 Mongrel servers…
sh: jrubycli: command not found
mongrel_rails start -e development -p 8000 -P log/mongrel.8000.pid
sh: jrubycli: command not found
mongrel_rails start -e development -p 8001 -P log/mongrel.8001.pid
Comment by sagi — September 18, 2009 @ 9:45 pm
sagi, I’ve not tried the configuration for sometime now. Please ask your question to .
Thanks,
-Arun
Comment by Arun Gupta — September 22, 2009 @ 10:09 pm