Search code examples
ruby-on-railsrubycronrbenvwhenever

After ruby update, crontab not working "bundler: not executable: bin/rails"


After ruby version was updated from 2.3.1 to 2.3.7, crontab is not executable in production environment (It's working in local environment). Before update, it was working.

I'm using rbenv, so the information which I could find in Internet to solve this kind of problem like ($rvm cron setup) is not suitable for my case.

schedule.rb code is:

env :PATH, ENV['PATH']
env :GEM_PATH, ENV['GEM_PATH']
rails_env = ENV['RAILS_ENV'] || :development
require File.expand_path(File.dirname(__FILE__) + "/environment")
set :environment, rails_env
set :output, "#{Rails.root}/log/cron.log"

 every 1.day do
  runner "Reminder.reminder_mail"
end

What strange is, ruby version shows

$ ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [x86_64-linux]

But the environment shows different ruby version..

$ bundle env
Ruby          2.3.1p112 (2016-04-26 revision 0) [x86_64-linux-gnu]

I don't know if this is a problem and how to solve.

Current setting for crontab is:

$ crontab -l
PATH=/home/franky/list/voendor/bundler/ruby/2.3.0/bin:/usr/local/bin:/home/franky/.gem/ruby/2.3.0/bin:/usr/local/rbenv/shims:~/.rbenv/shims:/usr/local/rbenv/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
GEM_PATH=””

0 0 * * * /bin/bash -l -c ‘cd /home/franky/list && bundle exec bin/rails runner -e production ‘'‘Reminder.reminder_mail’'’ » /home/franky/list/log/cron.log 2>&1’

Could someone help me to solve this problem?


Solution

  • I could solve this problem with "rake db:drop" and "rake db:create"!!! The crontab is working again!