From be7b246818985588590e4b520e46d2c81ed734b7 Mon Sep 17 00:00:00 2001 From: macournoyer Date: Sat, 9 Feb 2008 16:05:09 -0500 Subject: [PATCH] Fix -s option not being included in generated config file, fixes #37. --- CHANGELOG | 1 + lib/thin/controllers/cluster.rb | 36 ++++++++++++++---------------- lib/thin/controllers/controller.rb | 5 +++++ lib/thin/controllers/service.rb | 2 +- spec/controllers/cluster_spec.rb | 9 -------- 5 files changed, 24 insertions(+), 29 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 9c7b005b..eeba3eea 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,4 +1,5 @@ == 0.7.0 Bionic Pickle release + * Fix -s option not being included in generated config file, fixes #37. * Add Swiftiply support. Use w/ the --swiftiply (-y) option in the thin script, closes #28 [Alex MacCaw] diff --git a/lib/thin/controllers/cluster.rb b/lib/thin/controllers/cluster.rb index 4bec6595..da88a4a1 100644 --- a/lib/thin/controllers/cluster.rb +++ b/lib/thin/controllers/cluster.rb @@ -5,19 +5,15 @@ module Controllers # * Inject the port or socket number in the pid and log filenames. # Servers are started throught the +thin+ command-line script. class Cluster < Controller - # Number of servers in the cluster. - attr_accessor :size - + # Cluster only options that should not be passed in the command sent + # to the indiviual servers. + CLUSTER_OPTIONS = [:servers, :only] + # Create a new cluster of servers launched using +options+. def initialize(options) - @options = options.merge(:daemonize => true) - @size = @options.delete(:servers) - @only = @options.delete(:only) - - if socket - @options.delete(:address) - @options.delete(:port) - end + super + # Cluster can only contain daemonized servers + @options.merge!(:daemonize => true) end def first_port; @options[:port] end @@ -25,6 +21,8 @@ def address; @options[:address] end def socket; @options[:socket] end def pid_file; @options[:pid] end def log_file; @options[:log] end + def size; @options[:servers] end + def only; @options[:only] end def swiftiply? @options.has_key?(:swiftiply) @@ -39,7 +37,7 @@ def start def start_server(number) log "Starting server on #{server_id(number)} ... " - run :start, @options, number + run :start, number end # Stop the servers @@ -51,7 +49,7 @@ def stop def stop_server(number) log "Stopping server on #{server_id(number)} ... " - run :stop, @options, number + run :stop, number end # Stop and start the servers. @@ -89,8 +87,8 @@ def pid_for(number) private # Send the command to the +thin+ script - def run(cmd, options, number) - cmd_options = options.dup + def run(cmd, number) + cmd_options = @options.reject { |option, value| CLUSTER_OPTIONS.include?(option) } cmd_options.merge!(:pid => pid_file_for(number), :log => log_file_for(number)) if socket cmd_options.merge!(:socket => socket_for(number)) @@ -103,12 +101,12 @@ def run(cmd, options, number) end def with_each_server - if @only - yield @only + if only + yield only elsif socket || swiftiply? - @size.times { |n| yield n } + size.times { |n| yield n } else - @size.times { |n| yield first_port + n } + size.times { |n| yield first_port + n } end end diff --git a/lib/thin/controllers/controller.rb b/lib/thin/controllers/controller.rb index 72e4984a..d8e3c61a 100644 --- a/lib/thin/controllers/controller.rb +++ b/lib/thin/controllers/controller.rb @@ -19,6 +19,11 @@ class Controller def initialize(options) @options = options + + if @options[:socket] + @options.delete(:address) + @options.delete(:port) + end end def start diff --git a/lib/thin/controllers/service.rb b/lib/thin/controllers/service.rb index 9a98357c..51f52af9 100644 --- a/lib/thin/controllers/service.rb +++ b/lib/thin/controllers/service.rb @@ -10,7 +10,7 @@ class Service < Controller TEMPLATE = File.dirname(__FILE__) + '/service.sh.erb' def initialize(options) - @options = options + super raise PlatformNotSupported, 'Running as a service only supported on Linux' unless Thin.linux? end diff --git a/spec/controllers/cluster_spec.rb b/spec/controllers/cluster_spec.rb index a7692b6c..bf967357 100644 --- a/spec/controllers/cluster_spec.rb +++ b/spec/controllers/cluster_spec.rb @@ -19,10 +19,6 @@ @cluster.send(:include_server_number, 'thin.pid', 3000).should == 'thin.3000.pid' end - it "should exclude :servers option" do - @cluster.options.should_not have_key(:servers) - end - it 'should call each server' do calls = [] @cluster.send(:with_each_server) do |port| @@ -122,11 +118,6 @@ def options_for_socket(number) @cluster.silent = true end - it "should exclude :servers and :only options" do - @cluster.options.should_not have_key(:servers) - @cluster.options.should_not have_key(:only) - end - it 'should call only specified server' do calls = [] @cluster.send(:with_each_server) do |n|