在Heroku上使用realtime-rails gem和redis部署rails app

时间:2015-02-22 10:34:46

标签: ruby-on-rails node.js ruby-on-rails-4 heroku socket.io

我按照此处提供的模型构建了一个rails应用程序: http://mikeatlas.github.io/realtime-rails/

我正在使用Rails和realtime-rails gem和redis。我的应用程序在我的开发环境中工作,我想将它移动到Heroku。我已经在Redis-to-go中设置了Redis数据库,现在我想对realtime-gem和相关的socket-io服务器设置进行必要的更改。至少,我需要修改application_controller的生产部分:

def realtime_server_url
    if Rails.env.development?
        return 'HTTPLOCALHOST:5001'
    end
    if Rails.env.production?
        return 'PRODUCION-LOCATION'
    end
end

我已经将socket-io服务器(实时服务器)部署到一个单独的heroku实例,该服务器是通过上面的链接为实时服务器安装的。然后,我使用端口5001以及http和https为实时-server dyno创建了PRODUCION-LOCATION。没有快乐。

按照说明操作,在项目文件夹的顶层创建了realtime-server文件夹,与app文件夹并行。这是否意味着我应该将它包含在主存储库中,并以某种方式让它从与应用程序相同的dyno运行?如果是这样,我该如何开始呢?说明书说要在本地启动它:

 cd realtime-server
 foreman start

不清楚我是否可以通过heroku执行此操作cli将能够在同一个实例中运行以及它是如何启动的。

=============

更新

找到关于heroku的文档让我意识到,我需要为运行实时服务器的heroku dyno设置REDISCLOUD_URL:

heroku config:add REDISCLOUD_URL='redis_cloud_url'

并且在生产中它没有使用5001端口:

    if (process.env.NODE_ENV != 'production') {
        port = 5001; // run on a different port when in non-production mode.
    }

此外,找到了实时服务器强制执行HTTPS的表单控制台日志。

现在,阻塞问题似乎是来自实时服务器的/socket.io/socket.io.js的请求,它返回:

503 (Service Unavailable)

到目前为止,似乎将实时服务器与rails app存储库分开是正确的举措。

查看实时服务器的代码,以确定如何路由...

=====

更新

我看了你的建议日志,谢谢。看到实时服务器崩溃了,因为它不喜欢端口,所以我尝试将PORT变量443,3000,5001设置为各种使用无效:

heroku config:add PORT='443'

基于realtime-server的enviornment.js文件中的代码:

    var port = process.env.PORT || 5001;
    if (process.env.NODE_ENV != 'production') {
        port = 5001; // run on a different port when in non-production mode.
    }

这里是日志的摘录:

      2015-02-22T19:26:45.512317+00:00 heroku[api]: Set PORT config vars by tmt@breakthroughtek.com
      2015-02-22T19:26:45.512317+00:00 heroku[api]: Release v5 created by tmt@breakthroughtek.com
      2015-02-22T19:26:45.754327+00:00 heroku[web.1]: State changed from crashed to starting
      2015-02-22T19:26:48.318928+00:00 heroku[web.1]: Starting process with command `node forever.js`
      2015-02-22T19:26:49.540190+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
      2015-02-22T19:26:49.540213+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
      2015-02-22T19:26:49.957808+00:00 app[web.1]: STARTING ON PORT: 5001
      2015-02-22T19:27:44.163425+00:00 heroku[api]: Scale to web=1 by tmt@breakthroughtek.com
      2015-02-22T19:27:48.811493+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
      2015-02-22T19:27:48.811551+00:00 heroku[web.1]: Stopping process with SIGKILL
      2015-02-22T19:27:49.561043+00:00 heroku[web.1]: State changed from starting to crashed
      2015-02-22T19:27:49.561720+00:00 heroku[web.1]: State changed from crashed to starting
      2015-02-22T19:27:49.534451+00:00 heroku[web.1]: Process exited with status 137
      2015-02-22T19:27:51.936860+00:00 heroku[web.1]: Starting process with command `node forever.js`
      2015-02-22T19:27:53.289025+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
      2015-02-22T19:27:53.289046+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
      2015-02-22T19:27:53.703573+00:00 app[web.1]: STARTING ON PORT: 5001
      2015-02-22T19:28:51.991836+00:00 heroku[web.1]: Stopping process with SIGKILL
      2015-02-22T19:28:51.991836+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
      2015-02-22T19:28:52.758191+00:00 heroku[web.1]: Process exited with status 137
      2015-02-22T19:28:52.764783+00:00 heroku[web.1]: State changed from starting to crashed
      2015-02-22T19:31:22.240362+00:00 heroku[api]: Set PORT config vars by tmt@breakthroughtek.com
      2015-02-22T19:31:22.240362+00:00 heroku[api]: Release v6 created by tmt@breakthroughtek.com
      2015-02-22T19:31:22.378770+00:00 heroku[web.1]: State changed from crashed to starting
      2015-02-22T19:31:24.766187+00:00 heroku[web.1]: Starting process with command `node forever.js`
      2015-02-22T19:31:26.316332+00:00 app[web.1]: Detected 512 MB available memory, 512 MB limit per process (WEB_MEMORY)
      2015-02-22T19:31:26.316353+00:00 app[web.1]: Recommending WEB_CONCURRENCY=1
      2015-02-22T19:31:26.717561+00:00 app[web.1]: STARTING ON PORT: 5001

===========

更新

查看日志并看到系统仍在选择端口5001,我通过以下方式检查了heroku environement:

heroku config

并看到未设置NODE_ENV变量。做了一个:

heroku config:add NODE_ENV='production'

现在正在加载js文件。好极了!!! ..谢谢,d.danailov:)

必须解决heroku erring上的rails的一些问题,并且在访问管理区域时缺少模板错误:

    2015-02-22T20:04:36.492199+00:00 app[web.1]: Processing by LocationsController#index as HTML
    2015-02-22T20:04:36.497052+00:00 app[web.1]:   * "/app/app/views"
    2015-02-22T20:04:36.497054+00:00 app[web.1]:   * "/app/vendor/bundle/ruby/2.0.0/gems/devise-3.4.1/app/views"
    2015-02-22T20:04:36.497059+00:00 app[web.1]:   app/controllers/locations_controller.rb:8:in `index'
    2015-02-22T20:04:36.497050+00:00 app[web.1]: ActionView::MissingTemplate (Missing template locations/index, application/index with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in:
    2015-02-22T20:04:36.497062+00:00 app[web.1]: 
    2015-02-22T20:04:36.497057+00:00 app[web.1]: ):
    2015-02-22T20:04:36.497060+00:00 app[web.1]: 
    2015-02-22T20:04:36.497056+00:00 app[web.1]:   * "/app/vendor/bundle/ruby/2.0.0/gems/realtime-0.0.12/app/views"

当然,该页面在开发中运行良好。所以我将首先假设它与链轮/资产管道有关。

但我认为这部分可能会被解决。一旦我确认我可以发送实时消息,我将关闭。

=============

更新

已解决:请注意,不要在应用中的其他地方使用redis。 HEADS UP:我在初始化程序中有一个偷偷摸摸的小Redis.new,它正在消除我的Redis配置设置。

1 个答案:

答案 0 :(得分:0)

大部分解决方案是设置NODE_ENV& REDISCLOUD_URL用于在单独实例中运行的realitme服务器。