无法在生产服务器上为websocket-rails启动独立服务器



我正在尝试使用websocket-rails在我的应用程序上实现聊天系统。我的Gemfile看起来像:

Gemfile

source 'https://rubygems.org'

# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.1.1'
# Use sqlite3 as the database for Active Record
gem 'mysql2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.3'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
gem 'therubyracer',  platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 2.0'
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', '~> 0.4.0',          group: :doc

# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring',        group: :development
group :development, :test do
  gem 'byebug'
  gem 'annotate'
  gem 'better_errors'
  gem 'bullet'
  gem 'railroady'
  gem 'quiet_assets'
  gem 'jazz_hands'
end
gem 'thin'

# Use ActiveModel has_secure_password
gem 'bcrypt', '~> 3.1.7'
# Use unicorn as the app server
# gem 'unicorn'
gem 'unicorn' , group: :production
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
  gem 'capistrano','~> 2.15.5' , group: :development
  gem 'rvm-capistrano'
  gem 'capistrano-ext'
# Use debugger
# gem 'debugger', group: [:development, :test]
gem 'lorempixum', '~> 0.0.3'

gem 'kaminari'
gem "opentok", "~> 2.2"
gem 'slim'
gem 'pg'
gem 'rails_12factor', group: :production
gem 'private_pub'
gem 'devise'
gem 'redis'
gem 'websocket-rails'

配置初始化/websocket_rails.rb

WebsocketRails.setup do |config|
  # Uncomment to override the default log level. The log level can be
  # any of the standard Logger log levels. By default it will mirror the
  # current Rails environment log level.
  # config.log_level = :debug
  # Uncomment to change the default log file path.
  # config.log_path = "#{Rails.root}/log/websocket_rails.log"
  # Set to true if you wish to log the internal websocket_rails events
  # such as the keepalive `websocket_rails.ping` event.
  # config.log_internal_events = false
  # Change to true to enable standalone server mode
  # Start the standalone server with rake websocket_rails:start_server
  # * Requires Redis
  config.standalone = true
  # Change to true to enable channel synchronization between
  # multiple server instances.
  # * Requires Redis.
  config.synchronize = false
  # Prevent Thin from daemonizing (default is true)
  # config.daemonize = false
  # Uncomment and edit to point to a different redis instance.
  # Will not be used unless standalone or synchronization mode
  # is enabled.
  # config.redis_options = {:host => 'localhost', :port => '6379'}
  # By default, all subscribers in to a channel will be removed
  # when that channel is made private. If you don't wish active
  # subscribers to be removed from a previously public channel
  # when making it private, set the following to true.
  # config.keep_subscribers_when_private = false
  # Set to true if you wish to broadcast channel subscriber_join and
  # subscriber_part events. All subscribers of a channel will be
  # notified when other clients join and part the channel. If you are
  # using the UserManager, the current_user object will be sent along
  # with the event.
  # config.broadcast_subscriber_events = true
  # Used as the key for the WebsocketRails.users Hash. This method
  # will be called on the `current_user` object in your controller
  # if one exists. If `current_user` does not exist or does not
  # respond to the identifier, the key will default to `connection.id`
  # config.user_identifier = :id
  # Uncomment and change this option to override the class associated
  # with your `current_user` object. This class will be used when
  # synchronization is enabled and you trigger events from background
  # jobs using the WebsocketRails.users UserManager.
  # config.user_class = User
  # Supporting HTTP streaming on Internet Explorer versions 8 & 9
  # requires CORS to be enabled for GET "/websocket" request.
  # List here the origin domains allowed to perform the request.
  # config.allowed_origins = ['http://localhost:3000']
  config.standalone_port = 3245
end

在本地机器上,按照所述https://github.com/websocket-rails/websocket-rails/wiki/Standalone-Server-

启动服务器,一切正常
$ bundle exec rake websocket_rails:start_server
Websocket Rails Standalone Server listening on port 3245
$ ps -ef | grep 3245
sahil     8719  2290  4 11:50 ?        00:00:02 thin server (0.0.0.0:3245) [websocket_rails]                                                                                                                  
sahil     8771  3688  0 11:51 pts/1    00:00:00 grep 3245

服务器端返回

$ ps -ef | grep 3245
deploy    7249  1348  0 02:23 pts/0    00:00:00 grep --color=auto 3245

显然websocket_rails没有瘦服务器运行。生产服务器上可能出现什么问题?

您可能没有设置环境变量。为了解决类似的问题,在我们的生产服务器上,所有rails应用程序都在一个名为"passenger"的用户下运行。这个用户在配置文件脚本中有一个环境变量定义:

export RAILS_ENV="production"

我们为我们的capistrano用户做了同样的事情,所以资产预编译,服务器任务等都在正确的环境下运行。

相关内容

  • 没有找到相关文章

最新更新