Question

We've got our Rails (2.2.2) application running on a Tomcat7 server using warbler (1.2.1) and JRuby (1.5.6), but since we want to simplify deployment to multiple machines, we want to run the rake tasks, like db:migrate, under the tomcat WEB-INF location. We have packaged up the db folder along with all the migrations.

One way we've seen recommended online doesn't work:

java -jar lib/jruby-core-1.5.6.jar -S $JRUBY_HOME/bin/rake db:migrate RAILS_ENV=staging

/var/lib/jruby/bin/rake:9:in `require': no such file to load -- rubygems (LoadError)
        from /var/lib/jruby/bin/rake:9

After adding to ENV:

GEM_HOME=$JRUBY_HOME/lib/ruby/gems/1.8
RUBYLIB=$JRUBY_HOME/lib/ruby/site_ruby/1.8

The same command gives:

/var/lib/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:32 warning: already initialized constant RAKEVERSION
/var/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require': no such file to load -- fileutils (LoadError)
        from /var/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /var/lib/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:35
        from /var/lib/jruby/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake.rb:31:in `require'
        from /var/lib/jruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from /var/lib/jruby-1.5.6/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:29
        from /var/lib/jruby-1.5.6/lib/ruby/gems/1.8/gems/rake-0.8.7/bin/rake:19:in `load'
        from /var/lib/jruby/bin/rake:19

And if I just run:

jruby -S $JRUBY_HOME/bin/rake db:migrate RAILS_ENV=staging

I get a big callstack of gem errors resulting from the vendorized gems. (OutOfMemoryError, NUllPointerException, etc.. which isn't actually consistent between runs).

This question (How do I run rake rake tasks in a rails app which is served by tomcat with jruby war deployment?) had no bites on it either. Any suggestions are appreciated.

Cheers.

Was it helpful?

Solution

Turns out this command works

java -jar /var/lib/jruby/jruby-complete-1.5.6.jar -S rake  db:migrate RAILS_ENV=staging

as long as I download the jruby-complete jar and make sure I have the ENV:

RUBYLIB=$JRUBY_HOME/lib/ruby/site_ruby/1.8
GEM_HOME=$JRUBY_HOME/lib/ruby/gems/1.8

OTHER TIPS

I had this problem as well, but on Windows.

Based on this warbler issue, I was able to put together a Windows batch script to include in the deploy and make the DB setup simple for our SAs:

SET RAILS_ENV=production
SET BUNDLE_WITHOUT=development:test
SET BUNDLE_GEMFILE=Gemfile
SET GEM_HOME=gems
java -classpath "lib/*" org.jruby.Main -S rake db:create db:migrate db:seed
pause

Running this from the WEB-INF directory of the deployed app does the trick. I did need to add the db directory, Rakefile, and Windows batch script to my warble.rb config to make it all play nicely.

kares is actively working hard to get proper rake support in warbler, so this should be a "for now" answer (and there are certainly cleaner ways to go about it if I wasn't pressed by a deadline), but I figured I'd share anyway since it was a stumbling point.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top