【发布时间】:2015-11-09 09:48:37
【问题描述】:
我正在使用when 和dynamic_sitemaps gem 来生成站点地图。
这是我的 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
并从应用目录(当前)运行bundle exec whenever --update-crontab RAILS_ENV="production"。
UPD 2017
rvm cron setup 也可能有帮助
【问题讨论】:
标签: ruby-on-rails ubuntu cron rvm whenever