Search code examples
ruby-on-railsamazon-ec2cronwhenever

Rails cron Whenever gem error, bundle: command not found


I've read this post Whenever errors and tried to implement the recommendations to no avail. I'm still receiving '/bin/bash: bundle: command not found' error. On Amazon EC2.

which ruby

/usr/local/bin/ruby

which bundler

/usr/local/bin/bundler

schedule.rb

env :PATH, ENV['PATH']
require File.expand_path('../application', __FILE__)
set :output, "log/cron_log.log"

every 1.minutes do
  rake "calculate:calculate"
end

crontab -e

          • /bin/bash -l -c 'cd /srv/www/myapp/releases/20141022032959 && RAILS_ENV=development bundle exec rake calculate:calculate --silent >> log/cron_log.log 2>&1'

tail -f log/cron_log.log

/bin/bash: bundle: command not found

When I copy the command out of crontab and run it directly, everything works fine (cd /srv/www/myapp/releases/20141022032959 && RAILS_ENV=development bundle exec rake calculate:calculate --silent >> log/cron_log.log 2>&1). It's the prepending of /bin/bash that's messing this up.

How do I get schedule.rb / whenever gem to recognize correct PATH.


Solution

  • Forget about PATH settings in cron files. Setting the PATH does not work.

    Set the path to bundle explicitly in your config/schedule.rb

    set :bundle_command, "/usr/local/bin/bundle exec"
    

    Edit: exec added so that task can run