Class: Thin::Controllers::Cluster
Class Thin::Controllers::Cluster < Controller
(in files lib/thin/controllers/cluster.rb )Control a set of servers.
- Generate start and stop commands and run them.
- Inject the port or socket number in the pid and log filenames.
Servers are started throught the thin command-line script.
Includes
Methods
Public Class new(options)
Create a new cluster of servers launched using options.
[ show source ]
# File lib/thin/controllers/cluster.rb, line 13
13: def initialize(options)
14: super
15: # Cluster can only contain daemonized servers
16: @options.merge!(:daemonize => true)
17: end
Public Instance address()
[ show source ]
# File lib/thin/controllers/cluster.rb, line 20
20: def address; @options[:address] end
Public Instance first_port()
[ show source ]
# File lib/thin/controllers/cluster.rb, line 19
19: def first_port; @options[:port] end
Public Instance log_file()
[ show source ]
# File lib/thin/controllers/cluster.rb, line 23
23: def log_file; @options[:log] end
Public Instance log_file_for(number)
[ show source ]
# File lib/thin/controllers/cluster.rb, line 72
72: def log_file_for(number)
73: include_server_number log_file, number
74: end
Public Instance only()
[ show source ]
# File lib/thin/controllers/cluster.rb, line 25
25: def only; @options[:only] end
Public Instance pid_file()
[ show source ]
# File lib/thin/controllers/cluster.rb, line 22
22: def pid_file; @options[:pid] end
Public Instance pid_file_for(number)
[ show source ]
# File lib/thin/controllers/cluster.rb, line 76
76: def pid_file_for(number)
77: include_server_number pid_file, number
78: end
Public Instance pid_for(number)
[ show source ]
# File lib/thin/controllers/cluster.rb, line 84
84: def pid_for(number)
85: File.read(pid_file_for(number)).chomp.to_i
86: end
Public Instance restart()
Stop and start the servers.
[ show source ]
# File lib/thin/controllers/cluster.rb, line 56
56: def restart
57: stop
58: sleep 0.1 # Let's breath a bit shall we ?
59: start
60: end
Public Instance server_id(number)
[ show source ]
# File lib/thin/controllers/cluster.rb, line 62
62: def server_id(number)
63: if socket
64: socket_for(number)
65: elsif swiftiply?
66: [address, first_port, number].join(':')
67: else
68: [address, number].join(':')
69: end
70: end
Public Instance size()
[ show source ]
# File lib/thin/controllers/cluster.rb, line 24
24: def size; @options[:servers] end
Public Instance socket()
[ show source ]
# File lib/thin/controllers/cluster.rb, line 21
21: def socket; @options[:socket] end
Public Instance socket_for(number)
[ show source ]
# File lib/thin/controllers/cluster.rb, line 80
80: def socket_for(number)
81: include_server_number socket, number
82: end
Public Instance start()
Start the servers
[ show source ]
# File lib/thin/controllers/cluster.rb, line 32
32: def start
33: with_each_server { |n| start_server n }
34: end
Public Instance start_server(number)
Start a single server
[ show source ]
# File lib/thin/controllers/cluster.rb, line 37
37: def start_server(number)
38: log "Starting server on #{server_id(number)} ... "
39:
40: run :start, number
41: end
Public Instance stop()
Stop the servers
[ show source ]
# File lib/thin/controllers/cluster.rb, line 44
44: def stop
45: with_each_server { |n| stop_server n }
46: end
Public Instance stop_server(number)
Stop a single server
[ show source ]
# File lib/thin/controllers/cluster.rb, line 49
49: def stop_server(number)
50: log "Stopping server on #{server_id(number)} ... "
51:
52: run :stop, number
53: end
Public Instance swiftiply?()
[ show source ]
# File lib/thin/controllers/cluster.rb, line 27
27: def swiftiply?
28: @options.has_key?(:swiftiply)
29: end