bin/nutcracker-web in nutcracker-web-0.0.10 vs bin/nutcracker-web in nutcracker-web-0.0.11
- old
+ new
@@ -5,23 +5,24 @@
require 'nutcracker/web'
require 'optparse'
require 'fileutils'
require 'socket'
require 'open3'
+require 'uri'
-options = { stats_port: 22222 }
+options = { stats_uri: URI("tcp://localhost:22222") }
OptionParser.new do |opts|
opts.set_summary_indent " "
opts.banner = "Usage: nutcracker-web [web-options] -- [nutcracker-options]"
opts.separator ""
opts.separator "[web-options]"
opts.separator ""
-
- opts.on("-s", "--stats-port PORT", "Nutcracker stats port - #{options[:stats_port]}") do |v|
- options[:stats_port] = v.to_i
+
+ opts.on("-u", "--stats-uri URI", "Nutcracker stats uri, default is tcp://localhost:22222") do |v|
+ options[:stats_uri] = URI(v)
end
opts.on("-c","--config FILE", "Nutcracker cluster config file") do |v|
options[:config_file] = File.expand_path v
end
@@ -61,11 +62,11 @@
abort "Please specified nutcracker config file" if options[:config_file].nil?
abort "Can't find the specified config file @ #{options[:config_file]}" unless File.exists? options[:config_file]
args = ARGV.to_a
-args << "--stats-port" << options[:stats_port]
+args << "--stats-port" << options[:stats_uri].port
if options[:pid]
args << "--pid-file" << options[:nutcracker_pid]
at_exit { options.values_at(:pid,:nutcracker_pid).map(&FileUtils.method(:rm_rf)) }
end
@@ -86,14 +87,14 @@
end
if options[:launch_nutcracker]
nutcracker = Nutcracker.start(options.merge(args: args))
else
- if (TCPSocket.new('127.0.0.1',options[:stats_port]) rescue nil)
+ if (TCPSocket.new(options[:stats_uri].host,options[:stats_uri].port) rescue nil)
nutcracker = Nutcracker.attach(options)
else
- abort "Failed to attach, are you sure that Nutcracker is running ?\n" +
- "the specified stats port is closed ( #{options[:stats_port]} )\n" +
+ abort "Failed to attach, are you sure that Nutcracker is running ?\n" +
+ "the specified stats port is closed ( #{options[:stats_uri].host}:#{options[:stats_uri].port} )\n" +
"If you want to launch Nutcracker instance as well use the --launch switch"
end
end
server = nutcracker.use(:web, options)