Running rake tasks under Tomcat and JRuby

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

One of the ways we saw on the Internet does not 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 ran:

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

I get a large column of gem errors resulting from the sale of gems. (OutOfMemoryError, NUllPointerException, etc., Which is not really consistent between runs).

This question ( How do I run rake rake tasks in a rails application that is served by tomcat with jruby war deployment? ) Also has no bites. Any suggestions are welcome.

Greetings.

+4
source share
2 answers

Turns off this command, it works

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

while I load jruby-complete jar and make sure that I have ENV:

 RUBYLIB=$JRUBY_HOME/lib/ruby/site_ruby/1.8 GEM_HOME=$JRUBY_HOME/lib/ruby/gems/1.8 
+4
source

I had this problem, but on Windows.

Based on this warbler problem , I was able to compile a Windows script package to be included in the deployment and complete the database setup just 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 application does the trick. I needed to add the db directory, Rakefile and the Windows script package to my warble.rb configuration so that everything was fine.

kares is actively working to get the right rake support in warbler, so this should be the answer "for now" (and of course there are cleaner ways to do this if I donโ€™t insist on a deadline), but I decided that I will share with you, as it was a stumbling block.

+2
source

Source: https://habr.com/ru/post/1338161/


All Articles