Skip to content

Commit 63e5ef1

Browse files
committedMar 17, 2014
Add a -b/-bind option per issue scoutapp#36
1 parent 986daa5 commit 63e5ef1

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed
 

‎Vagrantfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
Vagrant::Config.run do |config|
33
config.vm.box = "Ubunutu64-ruby2"
44
config.vm.box_url = "https://dl.dropboxusercontent.com/s/o5i10hcu57jamg8/ubuntu64-ruby2.box"
5-
config.vm.share_folder "foo", "/projects", "/Users/itsderek23/projects/"
5+
# config.vm.share_folder "foo", "/projects", "/Users/itsderek23/projects/"
66
config.vm.forward_port 5555,5555
7-
end
7+
end

‎bin/scout_realtime

+3-2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ Advanced options:
5656
EOS
5757

5858
opt :port, "point your web browser to this port to view realtime metrics.", :default => 5555, :short => "-p"
59+
opt :bind, "bind to this IP address on the host", :default => '0.0.0.0', :short => '-b'
5960
opt :foreground, "run in the foreground, i.e., don't daemonize the process. Useful for debugging.", :default => false, :short => "-f"
6061
opt :log_path, "full path for a log file", :default=>log_path
6162
opt :pid_path, "full path for a PID file", :default=>pid_path
@@ -81,7 +82,7 @@ EOS
8182
# TODO: should be able to pass :daemonize => !opts[:foreground] to Dante::Runner instead
8283
if opts[:foreground]
8384
puts " ** Initializing. cntl-c to stop. Logging to STDOUT **"
84-
Scout::Realtime::Main.instance(:port=>opts[:port]).go_sinatra
85+
Scout::Realtime::Main.instance(:port=>opts[:port],:bind=>opts[:bind]).go_sinatra
8586
puts startup_message
8687
else
8788
if command == :start
@@ -91,7 +92,7 @@ else
9192
end
9293

9394
Dante::Runner.new('scout_realtime').execute(:daemonize => !opts[:foreground], :pid_path => pid_path, :log_path => log_path, :port=>opts[:port]) do |options|
94-
Scout::Realtime::Main.instance(:port=>options[:port]).go_sinatra
95+
Scout::Realtime::Main.instance(:port=>options[:port],:bind=>opts[:bind]).go_sinatra
9596
end
9697
puts startup_message
9798
puts '* "scout_realtime stop" to stop the daemon'

‎lib/scout_realtime/main.rb

+4-3
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ class Main
77

88
attr_accessor :running, :runner, :stats_thread
99

10-
# opts: {:port=>xxx}
10+
# opts: {:port=>xxx, bind=>'0.0.0.0'}
1111
def initialize(opts={})
1212
@port=opts[:port]
13+
@bind_address=opts[:bind] || '0.0.0.0'
1314
Scout::Realtime::logger=Logger.new(STDOUT)
1415
@stats_thread = Thread.new {}
1516
@runner = Scout::Realtime::Runner.new
@@ -50,12 +51,12 @@ def go_sinatra
5051
#end
5152

5253
start_thread
53-
Scout::Realtime::WebApp.run!(:port=>@port)
54+
Scout::Realtime::WebApp.run!(:port=>@port,:bind=>@bind_address)
5455
end
5556

5657
def go_webrick
5758
logger.info("starting web server ")
58-
server = WEBrick::HTTPServer.new(:Port => 5555, :AccessLog => [])
59+
server = WEBrick::HTTPServer.new(:Port => @port, :AccessLog => [], :BindAddress => @bind_address)
5960
server.mount '/', Scout::Realtime::WebServer
6061
trap 'INT' do
6162
server.shutdown

‎lib/scout_realtime/web_app.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class Scout::Realtime::WebApp < Sinatra::Base
1111
set :static, true # set up static file routing
1212
set :public_dir, File.expand_path('../web', __FILE__) # set up the static dir (with images/js/css inside)
1313
set :views, File.expand_path('../web/views', __FILE__) # set up the views dir
14-
set :bind, "0.0.0.0" # necessary for running on vagrant
14+
set :bind, self.bind || "0.0.0.0" # 0.0.0.0 is the default and is required for Vagrant
1515
#set :traps, false # setting this to false means 1) sinatra won't capture any interrupts or term signals; 2) we need to call Scout::Realtime::WebApp.quit! ourselves in our own signal trap
1616

1717
#helpers Sinatra::ContentFor

0 commit comments

Comments
 (0)
Please sign in to comment.