3

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!

Muntasim
  • 6,689
  • 3
  • 46
  • 69
Niels
  • 599
  • 5
  • 28
  • Is the `bundle` command actually installed on your system in one of the directories listed in your `PATH` variable? What's the output of `which bundle`? – Stuart M Feb 09 '13 at 21:29
  • yes it is, `which bindle` returns: /usr/local/bin/bundle. If you look at the PATH specified above you will see /usr/local/bin included. And when I run a bundle exec command it works on that machine. – Niels Feb 16 '13 at 18:09
  • Are you running whenever under the same user your Rails app is deployed with? – Dan Feb 22 '13 at 01:17
  • @Niels I'm having the same problem mate. No solution yet, but you're not alone. – vvohra87 Nov 16 '13 at 17:13
  • I bet @rubious_dan is right, your app is deployed with different user than whenever is using/you are testing with. – Mike Szyndel Dec 29 '13 at 14:20
  • @MichaelSzyndel I have been experiencing the same. How do I make them the same? – index Jan 07 '14 at 10:06
  • @index read capistrano/rvm docs carefully, this should be also answered on SO already – Mike Szyndel Jan 07 '14 at 10:45
  • Your cron is not working or the command that you want to execute via cron not working? Try to run this "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" directly on terminal. If it works means cron is not working. Sometimes there is timezone difference between local & server time. Check that too. – mandar.gokhale Jan 20 '14 at 17:19

2 Answers2

1

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

lsaffie
  • 1,764
  • 1
  • 17
  • 22
1

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

Rahul Chaudhari
  • 2,230
  • 21
  • 29