[英]Unable to start stand alone server for websocket-rails on production server
我正在嘗試使用websocket-rails在我的應用程序上實現類似於系統的聊天。 我的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'
和
config / initializers / 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用戶進行了同樣的操作,因此資產預編譯,服務器任務等都在正確的環境下運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.