RVM Notes

Patricio Cano edited this page May 14, 2013 · 6 revisions

I'm not sure where to put this, but I wanted to share this tidbit of info.

I was having an issue where I would see all these hanging /bin/bash processes calling runner and rake that were being fired off by cron. Turns out my .rvmrc file in my app folder was causing the problem. Rvm by default will prompt to trust or not trust the file. This causes bash to hang. The solution I used was to disable the prompt by adding this line to my user rvm file in ~/.rvmrc

rvm_trust_rvmrcs_flag=1

This tells rvm to trust all rvmrc files. This is documented here: http://wayneeseguin.beginrescueend.com/2010/08/22/ruby-environment-version-manager-rvm-1-0-0/

https://github.com/javan/whenever/issues#issue/110

The reason that the processes are hanging is because whenever generates crontab entries that first cd into the release path. So /u/apps/my_app/releases/201302121406 instead of /u/apps/my_app/current. By cd'ing into the release path RVM believes the .rvmrc file is unknown (even though we both know it really isn't). And since it's unknown, RVM is going to prompt you to trust it. At which point it hangs.

Another work around

If you don't want to set rvm_trust_rvmrcs_flag=1 the following works for me for a Rails3/bundler/capistrano/multi-stage application.

  1. Make config/deploy.rb look like this:

    set :whenever_environment, defer { stage }
    set :whenever_identifier, defer { "#{application}_#{stage}" }
    set :whenever_command, "bundle exec whenever"
    set :whenever_variables, defer { "'environment=#{rails_env}&current_path=#{current_path}'" }
    require 'whenever/capistrano'
    
  2. Make config/schedule.rb look like this:

    job_type :rake, "{ cd #{@current_path} > /dev/null; } && RAILS_ENV=:environment bundle exec rake :task --silent :output"
    job_type :script, "{ cd #{@current_path} > /dev/null; } && RAILS_ENV=:environment bundle exec script/:task :output"
    job_type :runner, "{ cd #{@current_path} > /dev/null; } && RAILS_ENV=:environment bundle exec rails runner ':task' :output"
    

The { cd #{@current_path} > /dev/null; } bit will result in cd'ing to to the 'current' direction of your application. The braces and redirection are there to suppress RVM's output of "using ruby@gemset" notification.

If all else fails

If you are still having problems with your cron jobs not executing or bash not accepting your .rvmrc file, you can try using the modified version of whenever located at https://github.com/Insomniware/whenever The modifications were made so that it calls rvm use before cd'ing into the release path. There might be other ways around it but for me (supernova32) it works the best with my setup. You might find it useful, too.