jam-cloud/websocket-gateway/bin/websocket_gateway

54 lines
1.8 KiB
Ruby
Executable File

#!/usr/bin/env ruby
# 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))[jamenv]
db_config = YAML::load(File.open(db_config_file))[jamenv]
ActiveRecord::Base.establish_connection(db_config)
# 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
if jamenv == "production"
ENV['NEW_RELIC_LOG'] = '/var/log/websocket-gateway/newrelic_agent.log'
one_meg = 1024 * 1024
Logging.logger.root.appenders = Logging.appenders.rolling_file("log/#{jamenv}.log", :truncate=>true, :age=>'daily', :size=>one_meg, :keep=>20)
else
ENV['NEW_RELIC_LOG'] = "#{Dir.pwd}/log/newrelic_agent.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
Server.new.run(:port => config["port"],
:emwebsocket_debug => config["emwebsocket_debug"],
:connect_time_stale => config["connect_time_stale"],
:connect_time_expire => config["connect_time_expire"],
:rabbitmq_host => config['rabbitmq_host'],
:rabbitmq_port => config['rabbitmq_port'])