在Passenger和Faye的Thin上部署我们的主要应用程序目前正在运行。但是我在从这个设置过渡到使用passenger的Faye时遇到了一些问题。
这里(https://github.com/faye/faye-websocket-ruby)建议我可以在Passenger单机版上运行Faye,并使用以下命令启动所述服务器
passenger start -p 9292然而,这在本地甚至不起作用。首先,它返回此错误,声明无法在以下位置找到faye.js
http://localhost:9292/faye?message=%5B%7B%22channel%22%3A%22%2Fmeta%2Fhandshake%22%2C%22version%22%3A%221.0%22%2C%22supportedConnectionTypes%22%3A%5B%22callback-polling%22%5D%2C%22id%22%3A%221%22%7D%5D&jsonp=__jsonp1__错误是这样
Failed to load resource: the server responded with a status of 404 (Not Found) 当您将浏览器更改到指定的位置时,它会显示
no route matches [GET] "/faye"查看乘客日志,似乎首先会遇到以下错误
Started GET "/faye" for 127.0.0.1 at 2014-05-09 10:04:23 -0700
ActionController::RoutingError (No route matches [GET] "/faye"):然后撞上这个
Started OPTIONS "/faye" for 127.0.0.1 at 2014-05-09 10:04:58 -0700
ActionController::RoutingError (No route matches [OPTIONS] "/faye"):在使用Thin运行时,我使用以下命令启动服务器
bundle exec rackup faye.ru -s thin --daemonize -E production在我尝试的passenger start和thin之间有一些不同,但最大的区别是faye.ru永远不会运行。我的faye.ru是基本的
require 'faye'
faye_server = Faye::RackAdapter.new(:mount => '/faye', :timeout => 45)
Faye::WebSocket.load_adapter('thin')
run faye_server要将它切换到Passenger,我知道我需要删除第三个line...but,然后呢?当我将其直接添加到我的config.ru文件中时,faye服务器最终接管了整个应用程序,这绝对不是我的目标。我认为把它放在初始化器中可能会起作用,但我遇到了以下错误:
undefined method `run' for main:Object (NoMethodError)我认为这是因为这不是一个.ru文件,而是一个.rb文件。
无论如何,我发现自己相当困惑,我肯定会感谢任何提示/方向。
编辑:
此网站(http://rubydoc.org/github/jamesotron/faye-rails/frames)状态
If you want to run faye-rails on passenger, make sure you are using passenger 4.0 standalone or passenger 4.0 on nginx 1.4+ for nginx with websocket support. Passenger on apache is not supported. Because passenger uses a multi-process model, you must use the faye redis backend. Add gem 'faye-redis' to your Gemfile and configure your routes like this:
config.middleware.use FayeRails::Middleware, mount: '/faye', :timeout => 25, server: 'passenger', engine: {type: Faye::Redis, host: 'localhost'}但是,我尝试将相关代码添加到我的application.rb中,其中包含几个配置命令
module App
class Application < Rails::Application但是简单地在下面添加(我所有的其他config.whatever都在那里)上面建议的代码就会导致这个错误
uninitialized constant App::Application::FayeRails (NameError)编辑:
添加了faye-rails gem,因为我是个笨蛋(参见评论)。这也需要添加
config.middleware.delete Rack::Lock因为(控制台输出)
faye-rails can't work when Rack::Lock is enabled, as it will cause
a deadlock on every request.然而,现在我遇到了这个错误
/Users/WEF6/.rvm/gems/ruby-1.9.3-p448/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in `require': cannot load such file -- passenger (LoadError)这一定与我在这篇文章中概述的一些更改有关,因为我上面概述了在本地成功启动乘客后,我是如何收到错误的。运行passenger now服务器抛出以下错误
Could not spawn process for group location#default: An error occured while starting up the preloader.
in 'void Passenger::ApplicationPool2::SmartSpawner::handleErrorResponse(Passenger::ApplicationPool2::SmartSpawner::StartupDetails &)' (SmartSpawner.h:455)
in 'string Passenger::ApplicationPool2::SmartSpawner::negotiatePreloaderStartup(Passenger::ApplicationPool2::SmartSpawner::StartupDetails &)' (SmartSpawner.h:566)
in 'void Passenger::ApplicationPool2::SmartSpawner::startPreloader()' (SmartSpawner.h:206)
in 'virtual ProcessPtr Passenger::ApplicationPool2::SmartSpawner::spawn(const Passenger::ApplicationPool2::Options &)' (SmartSpawner.h:752)
in 'void Passenger::ApplicationPool2::Group::spawnThreadRealMain(const SpawnerPtr &, const Passenger::ApplicationPool2::Options &, unsigned int)' (Implementation.cpp:804)
[ 2014-05-09 12:15:15.1055 71107/0x10c9ce000 agents/HelperAgent/RequestHandler.h:2222 ]: [Client 21] Cannot checkout session.
Error page:
cannot load such file -- passenger (LoadError)发布于 2014-05-10 03:25:42
您必须在您的gemfile中声明faye-rails gem,包括以下行:
'faye-rails', '~> 2.0.0'更新:
我认为你可以在你的application.rb中添加下面这行代码来解决机架锁问题
config.middleware.delete Rack::Lock我希望这对你有帮助。
发布于 2014-05-10 19:52:50
我注意到您在运行瘦系统时使用的是faye.ru。Phusion Passenger仅支持config.ru作为机架启动文件的文件名。也许解决方案就像将faye.ru重命名为config.ru一样简单?
https://stackoverflow.com/questions/23570507
复制相似问题