It seems there is multiple ways to configure rvm and use it on a crontab. Here I describe a method which be used on a client app
Let assume you want to launch rake stats
on production_app application and write the results on a file
The rake task needs to use the good ruby version. To find it you can explore $rvm_path
$ echo $rvm_path
> /home/deploy/.rvm
$ ls $rvm_path/wrappers
> ruby-2.1.5@production_app ruby-2.2.2@sweet_app
We get directory wrapper:/home/deploy/.rvm
and the wrapper name:ruby-2.1.5@production_app
The cron job need to do some steps before launch the task:
- First you need to go into the application directory:
/srv/rails_app/production_app
- Then call the wrapper
/home/deploy/.rvm/wrappers/ruby-2.1.5@production_app/rake
- And finally your task:
stats
$ crontab -l
00 16 * * * cd /srv/rails_app/production_app && /home/deploy/.rvm/wrappers/ruby-2.1.5@production_app/rake stats > /home/deploy/production_app_stats.txt --silent