RVM, Rake and Cron on Ubuntu
Tennnngh! I read countless blog posts, tried numerous approaches that I found and rebuilt the server more than a couple times. And finally I found what the missing piece was for getting a rake command to run in cron with rvm.
Most of the results I found (on stackoverflow) flagged the solution as adding the path to your rvm in your line item in crontab. Something like /home/username/.rvm/gems/rake my_awesome_task… etc. I tried every variation of that I could think of and got the same results.
I dont use cron every day so this was a revelation to me. I found out that you can set variables, environment variables in your crontab file.
So the solution was very simple. Edit the crontab like this.
-
crontab -e
Then at the top of the file (mine is the first line)
-
SHELL = /home/wylie/.rvm/bin/rvm-shell
Then my commands:
-
* 4 * * * /bin/bash -l -c ‘cd /path/to/app && RAILS_ENV=production rake mytask –silent’
Done.
Hope that saves someone some time.
Thanks! you saved my day!
Thank you so much! I wish it had saved me more time, but it ended my troubles. Strangely, if you pipe the error output to a log file, you’ll get “expr: syntax error” every time the job runs. However, the job still runs as far as I can tell.