Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails cron whenever, bundle: command not found

I am trying to use whenever to execute a rake task onces a day. Im getting this error

/bin/bash: bundle: command not found
/home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find bundler (>= 0) amongst [minitest-1.6.0, rake-0.8.7, rdoc-2.5.8] (Gem::LoadError)
        from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec'
        from /home/app/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/site_ruby/1.9.1/rubygems.rb:1210:in `gem'
        from /home/app/.rvm/gems/ruby-1.9.2-p180/bin/bundle:18:in `<main>'

Here is my crontab

# Begin Whenever generated tasks for: /home/af/www/app/releases/20120216172204/config/schedule.rb
PATH=/home/af/.rvm/gems/ruby-1.9.2-p180@global/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

0 0 * * * /bin/bash -l -c 'cd /home/af/www/app/releases/20120216172204 && rvm 1.9.1-p180; RAILS_ENV=production /home/af/.rvm/gems/ruby-1.9.2-p180/bin/bundle exec rake daily:stats --silent >> /home/af/www/app/releases/20120216172204/log/cron.log 2>&1'

# End Whenever generated tasks for: /home/af/www/app/releases/20120216172204/config/schedule.rb

I'm at a loss as to why it isn't working. If I run the command:

cd /home/af/www/app/releases/20120216172204 && rvm 1.9.1-p180; RAILS_ENV=production /home/af/.rvm/gems/ruby-1.9.2-p180/bin/bundle exec rake daily:stats --silent >> /home/af/www/app/releases/20120216172204/log/cron.log 2>&1

It works fine, not sure whats going on here.

like image 697
Josh Crowder Avatar asked Feb 28 '12 12:02

Josh Crowder


2 Answers

You can also ensure your PATH ends up in the crontab, by putting the following at the top of the schedule.rb file:

env :PATH, ENV['PATH']

https://groups.google.com/forum/#!msg/whenever-gem/yRLt3f2jrfU/Exu3xfCo8DAJ

If above solution don't work for you, try:

env :GEM_PATH, ENV['GEM_PATH']
like image 133
Dennis Kuczynski Avatar answered Oct 13 '22 22:10

Dennis Kuczynski


In my case I just ran :

rvm env --path -- ruby-version[@gemset-name]

Referring to cron job setup doc

Added new source line to the command for ruby path before bundle command in the crontab -e

source /usr/local/rvm/environments/ruby-1.9.3-p392;

Now the commands like as below:

Before:

0 4 * * * cd /home/current && bundle exec rake my_rake RAILS_ENV=production

After:

0 4 * * * cd /home/current && source /usr/local/rvm/environments/ruby-1.9.3-p392; bundle exec rake my_rake RAILS_ENV=production

Cheers!!!

like image 6
Sumit Munot Avatar answered Oct 13 '22 22:10

Sumit Munot