Class: Up::Ruby::Cluster
Instance Method Summary collapse
-
#initialize(app:, host: 'localhost', port: 3000, scheme: 'http', ca_file: nil, cert_file: nil, key_file: nil, pid_file: nil, logger: Logger.new(STDERR), workers: nil) ⇒ Cluster
constructor
A new instance of Cluster.
- #listen ⇒ Object
- #stop ⇒ Object
Methods inherited from Server
Constructor Details
#initialize(app:, host: 'localhost', port: 3000, scheme: 'http', ca_file: nil, cert_file: nil, key_file: nil, pid_file: nil, logger: Logger.new(STDERR), workers: nil) ⇒ Cluster
Returns a new instance of Cluster.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/up/ruby/cluster.rb', line 10 def initialize(app:, host: 'localhost', port: 3000, scheme: 'http', ca_file: nil, cert_file: nil, key_file: nil, pid_file: nil, logger: Logger.new(STDERR), workers: nil) super(app: app, host: host, port: port) @pid_file = pid_file @secret = Random.uuid @workers = workers || Etc.nprocessors @members = [] @localhost_addr = TCPSocket.getaddress('localhost') end |
Instance Method Details
#listen ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/up/ruby/cluster.rb', line 22 def listen raise "already running" unless @members.empty? ::Up.instance_variable_set(:@instance, self) @workers.times do @members << fork do @member_id = @members.size + 1 super end end File.write(@pid_file, Process.pid.to_s) if @pid_file puts "Server PID: #{Process.pid}" unless @member_id install_signal_handlers Process.waitall end end |
#stop ⇒ Object
39 40 41 42 43 44 |
# File 'lib/up/ruby/cluster.rb', line 39 def stop if Up::CLI::stoppable? kill_members super end end |