Ruby on Rails Cron Jobs OpsWroks or on any server

added on :: 9 June 2014

If you are using Amazon OpsWork there are two ways to do a Cron Job (here it is for a Ruby on Rails application). One being  log in to server write your own and the other being  Cron jobs with Chef.

Log in to server is what worked for me and it goes like below. Also make sure you are logged in as root (sudo su) and do 'crontab -e'

*/15 * * * * cd /srv/www/myappname/current; /usr/bin/env /usr/local/bin/ruby bin/rails runner -e production 'Mymodel.my_method'

Corn log is at /var/log/cron or if you like to tail it see what is happening now do 'tail -f /var/log/cron'

As OpsWorks dynamically add severs on runtime, I assume you don't want all your servers run cron jobs. So best to log in to the main 24/7 server and update crontab.

As for chef:

How to for OpsWorks cron at  and you could do similar


cron "job_name" do
  hour "1"
  minute "10"
  command %Q{
        cd /srv/www/myappname/current; /usr/bin/env /usr/local/bin/ruby bin/rails runner -e production "Mymodel.my_method"

How to with Chef at