Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Whenever gem is not executing task

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!

like image 754
Niels Avatar asked Jan 21 '26 02:01

Niels


2 Answers

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

like image 136
lsaffie Avatar answered Jan 23 '26 14:01

lsaffie


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

like image 32
Rahul Chaudhari Avatar answered Jan 23 '26 15:01

Rahul Chaudhari



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!