91 lines
3.5 KiB
Ruby
Executable File
91 lines
3.5 KiB
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
require 'yaml'
|
|
|
|
# establish database connection before including JamRuby
|
|
require 'active_record'
|
|
bin_dir = File.expand_path(File.dirname(__FILE__))
|
|
|
|
app_config_file = File.join(bin_dir, '..', 'config', 'application.yml')
|
|
db_config_file = File.join(bin_dir, '..', 'config', 'database.yml')
|
|
jamenv = ENV['JAMENV']
|
|
jamenv ||= 'development'
|
|
ENV['RUBY_ENV'] = ENV['RAILS_ENV'] = jamenv # set RUBY_ENV so that newrelic can find the mode
|
|
config = YAML::load(File.open(app_config_file), aliases: true)[jamenv]
|
|
db_config = YAML::load(File.open(db_config_file), aliases: true)[jamenv]
|
|
|
|
# Allow callers (such as web feature specs) to force websocket-gateway to
|
|
# use the same test database as Rails so websocket auth can see test users.
|
|
override_db_name = ENV['WSG_DATABASE_NAME']
|
|
if override_db_name && !override_db_name.empty?
|
|
db_config = db_config.merge('database' => override_db_name)
|
|
end
|
|
|
|
ActiveRecord::Base.establish_connection(db_config)
|
|
|
|
jam_instance = ENV['JAM_INSTANCE'] || 1
|
|
jam_instance = jam_instance.to_i
|
|
|
|
if jam_instance == 0
|
|
puts "JAM INSTANCE MUST BE > 0"
|
|
exit 1
|
|
end
|
|
|
|
#Resque.redis = "localhost:6380"
|
|
|
|
# now bring in the Jam code
|
|
require 'jam_websockets'
|
|
|
|
include JamWebsockets
|
|
|
|
# run some method
|
|
|
|
|
|
if config["verbose"]
|
|
Logging.logger.root.level = :debug
|
|
else
|
|
Logging.logger.root.level = :info
|
|
end
|
|
|
|
require "#{Dir.pwd}/config/application.rb"
|
|
|
|
|
|
if jamenv == "production"
|
|
ENV['NEW_RELIC_LOG'] = "/var/log/websocket-gateway/newrelic_agent-#{jam_instance}.log"
|
|
one_meg = 1024 * 1024
|
|
Logging.logger.root.appenders = Logging.appenders.rolling_file("/var/log/websocket-gateway/#{jamenv}-#{jam_instance}.log", :truncate=>true, :age=>'daily', :size=>one_meg, :keep=>20, :layout => Logging.layouts.pattern(:pattern => '[%d] %-5l: %m\n'))
|
|
else
|
|
ENV['NEW_RELIC_LOG'] = "#{Dir.pwd}/log/newrelic_agent-#{jam_instance}.log"
|
|
Logging.logger.root.appenders = Logging.appenders.stdout
|
|
end
|
|
|
|
# start monitoring
|
|
ENV['NRCONFIG'] = "#{Dir.pwd}/config/newrelic.yml"
|
|
require 'newrelic_rpm'
|
|
Object.send(:remove_const, :Rails) # this is to 'fool' new relic into not thinking this is a Rails app.
|
|
::NewRelic::Agent.manual_start
|
|
|
|
# determine gateway_name
|
|
gateway_name = ENV['GATEWAY_NAME'] || 'default'
|
|
gateway_name = "#{gateway_name}-#{jam_instance}"
|
|
|
|
Server.new.run(:port => config["port"] + (jam_instance - 1 ) * 2,
|
|
:emwebsocket_debug => config["emwebsocket_debug"],
|
|
:connect_time_stale_client => config["connect_time_stale_client"],
|
|
:connect_time_expire_client => config["connect_time_expire_client"],
|
|
:connect_time_stale_browser => config["connect_time_stale_browser"],
|
|
:connect_time_expire_browser => config["connect_time_expire_browser"],
|
|
:max_connections_per_user => config["max_connections_per_user"],
|
|
:rabbitmq_host => config['rabbitmq_host'],
|
|
:rabbitmq_port => config['rabbitmq_port'],
|
|
:influxdb_database => config['influxdb_database'],
|
|
:influxdb_username => config['influxdb_username'],
|
|
:influxdb_password => config['influxdb_password'],
|
|
:influxdb_hosts => config['influxdb_hosts'],
|
|
:influxdb_port => config['influxdb_port'],
|
|
:allow_dynamic_registration => config['allow_dynamic_registration'],
|
|
:cidr => config['cidr'],
|
|
:gateway_name => gateway_name,
|
|
:chat_enabled => config['chat_enabled'],
|
|
:chat_blast => config['chat_blast'])
|