RVM and Cron

Posted on 23 Aug 2011 by Eric Oestrich

Today I set up my first real rails production server and in the process ran across an issue with cron and rvm. I have a rake task that I want to run every 15 minutes. I made a script that cd’d into the directory, loaded the correct ruby and gemset then did the rake task.

Every time cron ran though, it kept giving me the following error:

rvm: command not found
rake: command not found

After some quick googling I came across two posts that let me do the rake task:

Sourcing the rvm script was the part I was missing.

This was the final script I came up with:

#!/bin/bash

source ~/.rvm/scripts/rvm
cd /home/deploy/apps/my_app
rvm use 1.9.2@my_app
RAILS_ENV=production rake email:reminder
comments powered by Disqus
Creative Commons License
This site's content is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License unless otherwise specified. Code on this site is licensed under the MIT License unless otherwise specified.