Whenever gem is not executing task

851 Views Asked by At

I set up a rails project to use the Whenever gem. Now I deploy my project with Capistrano and the tasks are nicely added to crontab list. But when I see only one line:

/bin/bash: bundle: command not found

So I read a couple of articles online so I added this on top of my schedule.rb file

env 'PATH', ENV['PATH']

So you should think problem solved, because this will add this next line to the crontab:

PATH=/var/rails/alfa_paints/shared/bundle/ruby/1.9.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

So you should think bundle is in the path when the command gets executed. But still no luck. I ran the command and the deployment with a seperate user. So to make sure everything runs with that user, deployer in this case. I asssumed the role of deployer and ran the command as specified in crontab. I didn't experience any problems when executing this command.

I'm running out of options and was wondering if anybody else experienced this strange behavior? I'm hoping for some advise. This is the output in my crontab:

# Begin Whenever generated tasks for: alfa_paints
 PATH=/var/rails/alfa_paints/shared/bundle/ruby/1.9.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

0 1 * * * /bin/bash -l -c 'cd /var/rails/alfa_paints/releases/20130127192223 && RAILS_ENV=production bundle exec rake alfa:cleanup --silent >> /var/rails/alfa_paints/shared/log/whenever.log 2>&1'

# End Whenever generated tasks for: alfa_paints

Any help welkom!

2

There are 2 best solutions below

0
On

Which shell are you using? Since I have seen whenever adds 'bash -l -c ' in job command. Either set

set :job_template, nil

or if you are using zsh then

set :job_template, "zsh -l -c ':job'"

This solved my issue

1
On

You'll need to pass in the necessary environment variables in crontab.

Add these lines at the top of your crontab (crontab -e)

(obviously you'll modify the values of the variables to represent those in your environment)

(in this case I'm using RVM)

PATH=/home/deploy/.rvm/gems/ruby-2.0.0-p247/bin:/home/deploy/.rvm/gems/ruby-2.0.0p247@global/bin:/home/deploy/.rvm/rubies/ruby-2.0.0p247/bin:/home/deploy/.rvm/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/bin/:/home/deploy/.rvm/bin

GEM_HOME=/home/deploy/.rvm/gems/ruby-2.0.0-p247

GEM_PATH=/home/deploy/.rvm/gems/ruby-2.0.0-p247/home/deploy/.rvm/gems/ruby-2.0.0-p247@global

MY_RUBY_HOME=/home/deploy/.rvm/rubies/ruby-2.0.0-p247