Using Foreman to run JRuby with RVM and MRI

Foreman is a utility written in Ruby that makes it easy to launch multiple processes with a single command and watch the output (which is color coded per process) on a single screen. If your application has multiple processes to start then Foreman might be a good solution for you (take a look at the Railscast on Foreman for a good introduction if you’re not familiar with it).

Inside Foreman makes use of Process#fork to launch its processes and unfortunately that isn’t supported by JRuby. If you’re using RVM to manage your Ruby installations you can use its wrapper functionality to create a wrapper for Foreman to run it using MRI (or another Ruby implementation that supports Process#fork). Here’s how you do it:

Assuming you’ve installed Ruby 1.9.2 using RVM and have installed the Foreman gem inside a gemset named “dev”. Type the following command to create a shortcut to run Foreman with 1.9.2 regardless of the Ruby you’ve activated using RVM: rvm wrapper 1.9.2@dev mri foreman

You’ll now be able to type mri_foreman to start Foreman using Ruby 1.9.2. Simply create a Procfile in your JRuby project and use “mri_foreman” where you’de use “foreman” and you’re good. For more information on how “rvm wrapper” works type “rvm help wrapper”.

If RVM isn’t your cup of tea and you really need something that works with JRuby directly you can use Guard with Guard::Process (which makes use of the spoon gem to launch commands which works in JRuby and CRuby) to start and run multiple processes.
Guard’s output isn’t nearly as readable as Foreman’s though (it doesn’t indicate which output came from which Guard with color coding), and controlling which how many of each process to start is strictly controlled through the Guardfile (whereas with Foreman you can influence this with the “foreman start” command using the -c flag), but it works!

About these ads
Follow

Get every new post delivered to your Inbox.

Join 157 other followers

%d bloggers like this: