javan / whenever

Cron jobs in Ruby
MIT License
8.82k stars 729 forks source link

Mina deploy and cron problems #616

Open AnubixXx opened 8 years ago

AnubixXx commented 8 years ago

Hi,

I have some issues with Whenever gem and Mina deploy.

In my schedule.rb I have:

env :PATH, ENV['PATH']

every 12.hours do
  rake "-s sitemap:refresh"
end

In deploy.rb I have:

require 'mina/whenever'
.................
and in deploy do
invoke :'whenever:clear'
invoke :'whenever:write'
invoke :'deploy:cleanup'

The reason why I don't use whenever:update is that it doesnt work correctly. It updated cron one deploy step back. Well, but it isn't that problem. This command create this crontab -l:

# Begin Whenever generated tasks for: 46.101.149.216_production
PATH=/home/thomas/myapp/releases/36/vendor/bundle/ruby/2.2.0/bin:/home/thomas/.rbenv/versions/2.2.3/bin:/home/thomas/.rbenv/libexec:/home/thomas/.rbenv/plugins/ruby-build/bin:/home/thomas/.rbenv/shims:/home/thomas/.rbenv/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

0 0,12 * * * /bin/bash -l -c 'cd /home/thomas/myapp/current && RAILS_ENV=production bundle exec rake -s sitemap:refresh --silent'

# End Whenever generated tasks for: 46.101.149.216_production

Well, it's really weird the PATH part. And of course, cron doesn't work. Maybe it's because env :PATH, ENV['PATH'], but before it didn't work as well. I am using rbenv. I have no idea how cron works and I can't repair it. But when I go to /home/thomas/myapp/current folder on server and run command manually, sitemap is created, so command works correctly.

Thanks for help.

attilahorvath commented 7 years ago

You shouldn't need to set the PATH in the schedule file. There might be something wrong with your rbenv setup though.

Are you sure the task runs correctly? Can you run this entire command line from the console?

cd /home/thomas/myapp/current && RAILS_ENV=production bundle exec rake -s sitemap:refresh --silent

Another issue could be that you're using different users. Are you sure you're using the same thomas user for deployments as well as running the app?

By the way, you don't need the -s option for your Rake command, since Whenever will automatically include --silent, which is the same thing.