via Deploy Hook

UPDATE 4.10.2013: Updating these instructions to use bundle exec, per chintan/Nic Pillinger
UPDATE 11.4.2013: Updating these instructions to use helper methods to determine which instances to run the command on

If you want your crontab updated by whenever on deploy, make a file named deploy/before_restart.rb and stick this in it:

on_app_master do
  # the following updates the crontab upon deployment
  run "cd #{config.release_path}; bundle exec whenever --set environment=#{config.framework_env} --update-crontab '#{}_#{config.framework_env}'"

This is called a ‘deploy hook’ and here’s more info.

via Deploy Hook using Binstubs

Since Engine Yard automatically installs your binstubs, you could also replace “bundle exec whenever” with “ey_bundler_binstubs/whenever”. If you want to be able to run “bin/whenever” you’ll have to symlink to ey_bundler_binstubs – but remember it’s in the current deploy directory, so you’ll have to do this per-deploy – which means you could stick this in the same before_restart.rb file (obviously it would need to be above the whenever block):

run "ln -nfs #{config.release_path}/ey_bundler_binstubs #{config.release_path}/bin"
on_app_master do
  # the following updates the crontab upon deployment
  run "cd #{config.release_path}; bin/whenever --set environment=#{config.framework_env} --update-crontab '#{}_#{config.framework_env}'"

Note for Utility Instances

UPDATE 11.4.2013: If you also want your cron jobs to work on all app servers (not just your app master), change “on_app_master” above to “on_app_servers”. For app servers and utilities, use “on_app_servers_and_utilities”. For utilities only, use “on_utilities”. As far as I can tell, there does not appear to be an option for only app master and utilities; if you need this, write two identical blocks with “on_app_master” and “on_utilities”.

via Custom Chef Recipes

Why would you also need to do a custom chef recipe? Because if you rebuild your cluster and don’t redeploy, your cron jobs won’t be created.

UPDATE 4.17.2012: If you’re on EY and not using custom chef recipes, you should start. A whenever recipe has been written and is detailed here. Info on how to start using custom chef recipes is here. It’s not so bad, really. One gotcha: your “appname” in the recipe is not your rails application name, but your EY application name – these can be different things!