jruby pass jvm arguments to rake task - jvm

How do i pass jvm arguments like Xmx to a rake task in jruby?
Am using rvm and running the rake task "rake db:migrate".
Thanks!

Rather that put the entire path, if jruby is already the Ruby you're using (for example, with rvm) such that just typing rake would be using jruby, you can use a double dash to send the arguments to the jvm.
Examples:
bundle exec rake -- -J-Xmx1024m (if you're using bundler)
rake -- -J-Xmx1024m

Found it!
jruby -J-Xmx2048m -S /home/prats/.rvm/gems/jruby-1.6.1#myapp/bin/rake db:migrate

Related

How to run tagged rspec tests with parallel_tests?

I want to execute my rspec tests in parallel
If I need all tests to perform on 6 cores I use bundle exec rake parallel:spec[6]
How can I specify a tag option for spec rake, e.g. --tag ~chat
Use SPEC_OPTS environment variable for passing options to rspec in this case.
Example:
$ SPEC_OPTS='--tag ~chat' bundle exec rake parallel:spec[6]

how to run rake task in background in rails

This is my command
bundle exec rake resque:work QUEUE="*" --trace
I want to run this command on my server as a background process.
please help me.
A method I often use is:
nohup bundle exec rake resque:work QUEUE="*" --trace > rake.out 2>&1 &
This will keep the task running even if you exit your shell. Then if I want to just observe trace output live, I do:
tail -f rake.out
And you can examine rake.out at any time.
If you need to kill it before completion, you can find it with ps and kill the pid.
Just in case somebody finds this 4 years later, bundle has an elegant way of doing this now. For example if you want to run sidekiq in the background you can do:
bundle exec sidekiq -e production -d -L ./log/sidekiq.log
The -d daemonizes to run in the background, but you will also need to use the -L to provide a logfile, else bundler will refuse to run your command in the background (deamonize).
Tested with bundler version 1.15.4
Update Oct 2019.
While the command still works in general, the specific command above will no longer work for sidekiq 6.0+, you'll need to use Upstart or Systemd if you use Linux: https://github.com/mperham/sidekiq/wiki/Deployment#running-your-own-process

rake db tasks disappear in deployment

I have a Rails 3.2.8 app which is running nicely in development on my machine, with Postgres as the db backend for ActiveRecord. However, when I deploy my code to an EC2 server, either via capistrano or by rsync'ing my project to the EC2 instance, rake no longer lists any of the db: tasks:
$ rake -T
rake about # List versions of all Rails frameworks and the environment
rake assets:clean # Remove compiled assets
rake assets:precompile # Compile all the assets named in config.assets.precompile
rake doc:app # Generate docs for the app -- also available doc:rails, doc:guides, doc:plugins (options: TEMPLATE=/rdoc-t...
rake load_gml # Load GML source files into the environment database
rake log:clear # Truncates all *.log files in log/ to zero bytes
rake middleware # Prints out your Rack middleware stack
rake notes # Enumerate all annotations (use notes:optimize, :fixme, :todo for focus)
rake notes:custom # Enumerate a custom annotation, specify with ANNOTATION=CUSTOM
rake rails:template # Applies the template supplied by LOCATION=(/path/to/template) or URL
rake rails:update # Update configs and some other initially generated files (or use just update:configs, update:scripts, or u...
rake routes # Print out all defined routes in match order, with names.
rake secret # Generate a cryptographically secure secret key (this is typically used to generate a secret for cookie se...
rake stats # Report code statistics (KLOCs, etc) from the application
rake test # Runs test:units, test:functionals, test:integration together (also available: test:benchmark, test:profil...
rake test:recent # Run tests for {:recent=>"test:prepare"} / Test recent changes
rake test:single # Run tests for {:single=>"test:prepare"}
rake test:uncommitted # Run tests for {:uncommitted=>"test:prepare"} / Test changes since last checkin (only Subversion and Git)
rake time:zones:all # Displays all time zones, also available: time:zones:us, time:zones:local -- filter with OFFSET parameter,...
rake tmp:clear # Clear session, cache, and socket files from tmp/ (narrow w/ tmp:sessions:clear, tmp:cache:clear, tmp:sock...
rake tmp:create # Creates tmp directories for sessions, cache, sockets, and pids
rake -P also reports no db: tasks.
I'm guessing it's some sort of dependency problem, but I can't see what that would be since I'm declaring all my gem dependencies in a Bundler Gemfile. Postgres 9.2.1 is installed and working, but even if it wasn't I don't get why the rake task would vanish.
Any clues as to what's going on gratefully received!
And it turns out to be stupid-simple: I had copied the deploy.rb file from a previous project which didn't use ActiveRecord, so I hadn't set the role db:. I'm still not sure why that meant that the rsync'ed copy of my project also didn't have any rake db: tasks, but I'm not going to spend any more cycles worrying about that.

rake aborted! no such file to load -- bundler/setup

I run a rake task every night via cron (as root), when it runs it gives the error:
rake aborted!
no such file to load -- bundler/setup
which I get in an email
When I run it manually (as root), it runs just fine.
I am running rvm if that helps.
I am not really sure what to add to help, but here are a few things.
# ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [i686-linux]
# rails -v
Rails 3.0.9
# gem -v
1.8.5
try to set up your cron task like this
* * * * * /bin/bash -l -c 'rake blah:blah'

RVM & Unicorn deploy

My RVM is installed as root.
When I'm trying to start unicorn socket, it prints
user#9001-3:~$ /etc/init.d/unicorn start
Starting myapp app: /usr/bin/env: ruby: No such file or directory
unicorn.
But if I type
user#9001-3:~$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-linux]
/usr/local/rvm/gems/ruby-1.9.2-p180/bin/unicorn path exists.
My unicorn config: https://gist.github.com/1010519
/etc/init.d/unicorn doesn't know where to find Ruby because it's managed via RVM. Normally, your .bashrc or similar file is executed and sets up the environment; this doesn't happen in init scripts (or likely anything else executed by root).
The solution is to use wrappers. For example, to create a binary called system_ruby that loads up RVM's 1.9.2p180 environment and then executes ruby, execute the following:
rvm wrapper ruby-1.9.2-p180 system ruby
For more information and more details, check out this answer of mine, which addresses a similar problem.
Symlink also works,
which ruby<your version>
ln-s /ruby/path/ruby<your version> /ruby/path/ruby
Type :
which ruby (show the ruby bin path) then type this : ln -s (change_to_ruby_path) /usr/bin/env/ruby (construct the correct access for your system)
I had the same problem and this for me
rvm --default use <version>