简体   繁体   中英

Could not locate Gemfile or .bundle/ directory --— rvm | cron | ubuntu | whenever

I'm using whenever and dynamic_sitemaps gems to generate sitemaps.

here's my schedule.rb

job_type :rake, "{ cd #{@current_path} > /dev/null; } && RAILS_ENV=:environment bundle exec rake :task --silent :output"
job_type :script, "{ cd #{@current_path} > /dev/null; } && RAILS_ENV=:environment bundle exec script/:task :output"
job_type :runner, "{ cd #{@current_path} > /dev/null; } && RAILS_ENV=:environment bundle exec rails runner ':task' :output"

set :output, "#{path}/log/cron.log"

every 1.day, :at => '5:30 am' do  
  rake "sitemap:generate"        
end

if I use " bundle exec rake sitemap:generate RAILS_ENV="production" " my sitemap is generated properly.

`bundle exec whenever RAILS_ENV="production"` seems to be working too  

-

30 5 * * * /bin/bash -l -c '{ cd > /dev/null; } && RAILS_ENV=production bundle exec rake sitemap:generate --silent >> /var/www/.*******.log 2>&1'

## [message] Above is your schedule file converted to cron syntax; your crontab file was not updated.
## [message] Run `whenever --help' for more options.

But when I check cron.log on another day(after 5:30) I see this message

Could not locate Gemfile or .bundle/ directory

So, the new sitemap wasn't generated. How can I fix this?

already tried this solution but it didn't work for me or I'm doing something wrong.

I installed ruby with rvm


UPDATE

So, I made it working. And here's what I did:

ls /usr/local/rvm/wrappers/

This gave me a list of wrappers/aliases that I have. One of them was ruby-2.2.2

then I edited my schedule.rb

set :output, "#{path}/log/cron.log"
job_type :runner, "cd #{path} && RAILS_ENV=production /home/$USER/.rvm/wrappers/ruby-2.2.2/bundle exec rails runner ':task' :output"

every 1.day, :at => '4:30 am' do
  rake "sitemap:generate"
end

and run bundle exec whenever --update-crontab RAILS_ENV="production" from the app directory(current).

UPD 2017

rvm cron setup might be helpful too

The problem is that when cron is executed, it won't load the rvm environment. There are several approaches to solve this. The RVM documentation has all the information you need - https://rvm.io/deployment/cron

It changed directory to home ( cd > /dev/null; ) since @current_path is nil.

It should work if you delete the first 3 lines. ( https://github.com/javan/whenever/blob/master/lib/whenever/setup.rb )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM