Skip to content

Commit

Permalink
Fix -s option not being included in generated config file, fixes #37.
Browse files Browse the repository at this point in the history
  • Loading branch information
macournoyer committed Feb 9, 2008
1 parent 704af39 commit be7b246
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 29 deletions.
1 change: 1 addition & 0 deletions 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]

Expand Down
36 changes: 17 additions & 19 deletions lib/thin/controllers/cluster.rb
Expand Up @@ -5,26 +5,24 @@ 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
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)
Expand All @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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))
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions lib/thin/controllers/controller.rb
Expand Up @@ -19,6 +19,11 @@ class Controller

def initialize(options)
@options = options

if @options[:socket]
@options.delete(:address)
@options.delete(:port)
end
end

def start
Expand Down
2 changes: 1 addition & 1 deletion lib/thin/controllers/service.rb
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions spec/controllers/cluster_spec.rb
Expand Up @@ -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|
Expand Down Expand Up @@ -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|
Expand Down

0 comments on commit be7b246

Please sign in to comment.