Whenever gem won't update crontab tasks

2020-07-18 06:12发布

问题:

I have been using the whenever gem on my 2+ year old slice at Slicehost. I can't however do the same on my new slice.

Main differences is that I'm now running RVM on both my MBP and the slice. I am also running Rails 3. I've got Rubygems v 1.5.0 and latest versions of RVM , Ruby 1.9.2p136, Capistrano and about every other package out there.

I have tried a million things, read all the docs and as of now I'm using the whenever gem version 0.6.2. I have also looked at all questions on related topics on SO as well as Google.

Here is the code in deploy.rb:

namespace :deploy do
  ...
  desc "Update the crontab file"
  task :update_crontab, :roles => :db do
    run "cd #{release_path} && whenever --update-crontab #{application}"
  end   
end

after 'deploy:update_code', 'deploy:update_crontab'

Here is the error message I get after running 'cap deploy'

failed: "rvm_path=$HOME/.rvm/ $HOME/.rvm/bin/rvm-shell '1.9.2' -c 'cd /home/deploy/public_html/lasource/releases/20110209201551 && /home/deploy/.rvm/gems/ruby-1.9.2-p136/bin/whenever --write-crontab'" on lasource.ohlalaweb.com

Any suggestions will be welcome.

By the way, where are the capistrano logs?

Having added 'bundle exec' thanks to the Simone's suggestion, I managed to complete the cap deploy routine as it everything went well. The new problem however is that my crontab file is still empty of tasks and did not create my section with its 4 tasks.

回答1:

If using Rails 3, remember to execute the command with bundle exec.

namespace :deploy do
  desc "Update the crontab file"
  task :update_crontab, :roles => :app, :except => { :no_release => true } do
    run "cd #{release_path} && bundle exec whenever --update-crontab #{application}"
  end
end


回答2:

According to the whenever's README:

If a :path is not set it will default to the directory in which whenever was executed.

So you shouldn't have to cd in a folder. Also, have you tried using the other ways of calling a shell command? I'm using backticks and it is working in my env

namespace :deploy do
  desc "Update the crontab file"
  task update_crontab: :environment do
    `whenever -i cellar`
  end
end