Class: Thin::Controllers::Cluster
Overview
Control a set of servers.
Servers are started throught the thin
command-line script.
Constant Summary
collapse
- CLUSTER_OPTIONS =
Cluster only options that should not be passed in the command sent to the indiviual servers.
[:servers, :only]
Instance Attribute Summary
Attributes inherited from Controller
#options
Instance Method Summary
collapse
Methods inherited from Controller
#config
Methods included from Logging
#debug, debug, debug?, #log, log, #log_error, log_error, #silent, #silent=, silent?, #trace, trace, trace?
Constructor Details
#initialize(options) ⇒ Cluster
Create a new cluster of servers launched using options
.
13
14
15
16
17
|
# File 'lib/thin/controllers/cluster.rb', line 13
def initialize(options)
super
@options.merge!(:daemonize => true)
end
|
Instance Method Details
#address ⇒ Object
20
|
# File 'lib/thin/controllers/cluster.rb', line 20
def address; @options[:address] end
|
#first_port ⇒ Object
19
|
# File 'lib/thin/controllers/cluster.rb', line 19
def first_port; @options[:port] end
|
#log_file ⇒ Object
23
|
# File 'lib/thin/controllers/cluster.rb', line 23
def log_file; @options[:log] end
|
#log_file_for(number) ⇒ Object
72
73
74
|
# File 'lib/thin/controllers/cluster.rb', line 72
def log_file_for(number)
include_server_number log_file, number
end
|
#only ⇒ Object
25
|
# File 'lib/thin/controllers/cluster.rb', line 25
def only; @options[:only] end
|
#pid_file ⇒ Object
22
|
# File 'lib/thin/controllers/cluster.rb', line 22
def pid_file; @options[:pid] end
|
#pid_file_for(number) ⇒ Object
76
77
78
|
# File 'lib/thin/controllers/cluster.rb', line 76
def pid_file_for(number)
include_server_number pid_file, number
end
|
#pid_for(number) ⇒ Object
84
85
86
|
# File 'lib/thin/controllers/cluster.rb', line 84
def pid_for(number)
File.read(pid_file_for(number)).chomp.to_i
end
|
#restart ⇒ Object
Stop and start the servers.
56
57
58
59
60
|
# File 'lib/thin/controllers/cluster.rb', line 56
def restart
stop
sleep 0.1 start
end
|
#server_id(number) ⇒ Object
62
63
64
65
66
67
68
69
70
|
# File 'lib/thin/controllers/cluster.rb', line 62
def server_id(number)
if socket
socket_for(number)
elsif swiftiply?
[address, first_port, number].join(':')
else
[address, number].join(':')
end
end
|
#size ⇒ Object
24
|
# File 'lib/thin/controllers/cluster.rb', line 24
def size; @options[:servers] end
|
#socket ⇒ Object
21
|
# File 'lib/thin/controllers/cluster.rb', line 21
def socket; @options[:socket] end
|
#socket_for(number) ⇒ Object
80
81
82
|
# File 'lib/thin/controllers/cluster.rb', line 80
def socket_for(number)
include_server_number socket, number
end
|
#start ⇒ Object
32
33
34
|
# File 'lib/thin/controllers/cluster.rb', line 32
def start
with_each_server { |n| start_server n }
end
|
#start_server(number) ⇒ Object
37
38
39
40
41
|
# File 'lib/thin/controllers/cluster.rb', line 37
def start_server(number)
log "Starting server on #{server_id(number)} ... "
run :start, number
end
|
#stop ⇒ Object
44
45
46
|
# File 'lib/thin/controllers/cluster.rb', line 44
def stop
with_each_server { |n| stop_server n }
end
|
#stop_server(number) ⇒ Object
49
50
51
52
53
|
# File 'lib/thin/controllers/cluster.rb', line 49
def stop_server(number)
log "Stopping server on #{server_id(number)} ... "
run :stop, number
end
|
#swiftiply? ⇒ Boolean
27
28
29
|
# File 'lib/thin/controllers/cluster.rb', line 27
def swiftiply?
@options.has_key?(:swiftiply)
end
|