Issue
I am using:
Ruby 1.9.3
whenever 0.9.4
Rails 3.2
and capistrano/whenever extension.
Whenever the deployment happens, it adds entries to the crontab file after each deployment. Since 5 deployments, there are 40 entries in crontab -l
, as schedule.rb has 8 cron entries. For each release there are different entries. Should it not overwrite the entries by default?
It recreates entries everytime mentioned in schedule.rb
file.
Solution
I found that whenever was adding a cron job to the crontab file, with each cron job delimited by a comment line that includes the path to the capistrano releases directory... something like this:
# Begin Whenever generated tasks for: /home/path/www/to/releases/2070527160502/config/schedule.rb
(You can look at the raw crontab file with crontab -e to see what whenever has put in there)
When the next deploy occurs, whenever looks to see if there are comment-delimited cron jobs, but using the new release number. It doesn't find that, so it appends new jobs to the crontab file.
My workaround for this problem is to specify the update_crontab task in deploy.rb with the explicit path to schedule.rb like this:
namespace :deploy do
task :update_crontab do
on roles(:all) do
within current_path do
execute :bundle, :exec, :whenever, "--update-crontab", "~/path/to/current/config/schedule.rb"
end
end
end
end
after 'deploy:symlink:release', 'deploy:update_crontab'
So the comment delimiters in the crontab file contain the 'current' path and not the 'releases/nnnnnnnnnnn' path.
I suspect that this should not be necessary, but after trying to solve the problem for some time, this what what I ended up with.
Answered By - Les Nightingill Answer Checked By - Timothy Miller (WPSolving Admin)