【发布时间】:2013-04-17 07:48:47
【问题描述】:
我已经阅读了该站点上的许多问题以及 ExceptionNotifier 的 GitHub 文档及其在 Rails 3 中的实现,但我不明白为什么它在我的生产服务器上不适合我。在我的本地机器(Mac)上,它可以在生产环境中完美运行。但是在我使用 capistrano 部署并在 Linux 机器上使用 unicorn 运行应用程序后,我的 unicorn 日志抱怨我的环境/production.rb 文件中有一个uninitialized constant ExceptionNotifier,即使我的本地机器似乎认为它很好。我已经尝试了两种实现:
gem 'exception_notification', :require => 'exception_notifier' 和
gem 'exception_notification_rails3', :require => 'exception_notifier'。两者都抛出此错误。这是我的制作.rb
Rl4::Application.configure do
# code omitted
# Enable ExceptionNotifier, having it ignore its default exceptions
config.middleware.use ExceptionNotifier,
sender_address: 'reports@ctatechs.com',
exception_recipients: 'brice@ctatechs.com',
ignore_exceptions: ExceptionNotifier.default_ignore_exceptions
end
这是我的 Gemfile
source 'https://rubygems.org'
# lots omitted
gem 'exception_notification_rails3', :require => 'exception_notifier'
# lots more omitted
这是我的 application_controller.rb,它实现了 gem:
class ApplicationController < ActionController::Base
protect_from_forgery
# By default, only production ENV considers requests not local
unless Rails.application.config.consider_all_requests_local
rescue_from Exception, :with => :server_error
rescue_from ActionController::UnknownAction, :with => :not_found
rescue_from ActionController::UnknownController, :with => :not_found
rescue_from ActionView::MissingTemplate, :with => :not_found
end
private
def server_error(exception)
ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver
respond_to do |format|
format.html { render template: '/500.html', layout: 'application/layout', status: 500 }
format.all { render nothing: true, status: 500 }
end
end
def not_found(exception)
ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver
respond_to do |format|
format.html { render template: '/404.html', layout: 'application/layout', status: 404 }
format.all { render nothing: true, status: 404 }
end
end
end
同样,目前实施不是我的问题。不知何故,gem 未正确安装或未正确初始化。我确实在 Linux 机器上为 gem 的两个版本以及“exception_notifier”运行了 sudo gem install。没有骰子。想法?
其他信息
我只是尝试将 gem 重新安装为插件,并在将 production.rb 文件更改为使用 config.middleware.use ::ExceptionNotifier 后得到相同的错误。但是,这些修改仍然适用于我的本地计算机。也许我错过了 Linux 机器上的另一个软件?文档中似乎没有提到任何内容...
请求 gem 版本
我正在使用 exception_notification,v. 3.0.1
请求完整的堆栈跟踪
I, [2013-04-24T17:34:44.113788 #16877] INFO -- : Refreshing Gem list
E, [2013-04-24T17:34:46.562588 #16877] ERROR -- : uninitialized constant ExceptionNotifier (NameError)
/home/deployer/rl4/releases/20130424201053/config/environments/production.rb:80:in `block in <top (required)>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:24:in `class_eval'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:24:in `configure'
/home/deployer/rl4/releases/20130424201053/config/environments/production.rb:1:in `<top (required)>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/engine.rb:571:in `block in <class:Engine>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `instance_exec'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:30:in `run'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:55:in `block in run_initializers'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `each'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/initializable.rb:54:in `run_initializers'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/application.rb:136:in `initialize!'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/railties-3.2.11/lib/rails/railtie/configurable.rb:30:in `method_missing'
/home/deployer/rl4/releases/20130424201053/config/environment.rb:5:in `<top (required)>'
config.ru:4:in `require'
config.ru:4:in `block in <main>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
config.ru:1:in `new'
config.ru:1:in `<main>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn.rb:44:in `eval'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn.rb:44:in `block in builder'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:722:in `call'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:722:in `build_app!'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:595:in `init_worker_process'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:615:in `worker_loop'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:500:in `spawn_missing_workers'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:511:in `maintain_worker_count'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/lib/unicorn/http_server.rb:277:in `join'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/gems/unicorn-4.6.2/bin/unicorn:126:in `<top (required)>'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/bin/unicorn:19:in `load'
/home/deployer/rl4/shared/bundle/ruby/1.9.1/bin/unicorn:19:in `<main>'
【问题讨论】:
-
但是你为什么同时使用
exception_notification和exception_notifier呢?我认为只需exception_notification就足够了。此外exception_notifier不是exception_notification的要求。最后一件事exception_notifier和exception_notification_rails是过时的宝石,距离上一个版本已有近 3 年的时间。你绝对应该只使用exception_notification。 -
感谢您的评论,但取出需求也没有解决它。另一台服务器上的生产应用程序仍未确认该库。
-
您使用的是什么
exception_notification版本?什么是完整的堆栈跟踪错误?您是否尝试过使用ExceptionNotifier.notify_exception而不是ExceptionNotifier::Notifier.exception_notification? github.com/smartinez87/… -
@AlterLagos 我刚刚在 gem 版本和堆栈跟踪中添加。我不确定我是否在任何地方调用了错误的方法,因为当我将配置包含在我的 production.rb 中时,应用程序甚至无法启动。未初始化常量
ExceptionNotifier的投诉 -
使用 capistrano 部署时会出现此错误,对吗?您是否尝试过在生产环境中手动执行应用程序以查看是否有效?如果您在暂存模式下手动运行,但在 prod 服务器中它可以工作吗?过去我在使用 bundler 和 capistrano 时遇到了一些问题,尽管当您登录服务器时可以看到已安装 gem,但并未安装所有 gem。以前在没有 gem 的情况下工作过吗?我也知道有时 Gemfile 中的 gem 顺序很重要。您使用的是 rvm 还是纯红宝石?我只是在猜测,但我希望其中一个能给你一个线索
标签: ruby-on-rails linux email production-environment exception-notification