无法找到Gemfile或.bundle /目录----- rvm | cron | ubuntu |每当

时间:2015-08-16 19:04:07

标签: ruby-on-rails ubuntu cron rvm whenever

我随时使用dynamic_sitemaps gems来生成站点地图。

这是 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

如果我使用" bundle exec rake sitemap:generate RAILS_ENV="production""我的站点地图生成正确。

`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.

但是当我在另一天(5:30之后)检查cron.log时,我看到了这条消息

Could not locate Gemfile or .bundle/ directory

因此,新网站地图尚未生成。 我该如何解决这个问题?

已经尝试this solution,但它对我没有用,或者我做错了。

我用 rvm

安装了ruby

更新

所以,我让它发挥作用。这就是我的所作所为:

ls /usr/local/rvm/wrappers/

这给了我一个包含/别名的列表。其中一个是ruby-2.2.2

然后我编辑了我的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

并从app目录(当前)运行bundle exec whenever --update-crontab RAILS_ENV="production"

UPD 2017

rvm cron setup也可能有帮助

2 个答案:

答案 0 :(得分:1)

问题是当执行cron时,它不会加载rvm环境。有几种方法可以解决这个问题。 RVM文档包含您需要的所有信息 - https://rvm.io/deployment/cron

答案 1 :(得分:1)

由于cd > /dev/null;为零,因此将目录更改为主页(@current_path)。

如果删除前3行,它应该有效。 (https://github.com/javan/whenever/blob/master/lib/whenever/setup.rb

相关问题