Class: Daemon::Cluster

Inherits:
Base show all
Defined in:
lib/serverside/cluster.rb

Overview

Implements a cluster controlling daemon. The daemon itself itself forks a child process for each port.

Constant Summary collapse

@@pids =
[]

Class Method Summary collapse

Methods inherited from Base

pid_fn

Class Method Details

.daemon_loopObject

The main daemon loop. Does nothing for now.



28
29
30
# File 'lib/serverside/cluster.rb', line 28

def self.daemon_loop
  loop {sleep 60}
end

.fork_server(port) ⇒ Object

Forks a child process with a specific port.



8
9
10
11
12
13
# File 'lib/serverside/cluster.rb', line 8

def self.fork_server(port)
  fork do
    trap('TERM') {exit}
    server_loop(port)
  end
end

.startObject

Starts child processes and calls the main loop.



33
34
35
36
# File 'lib/serverside/cluster.rb', line 33

def self.start
  start_servers
  daemon_loop
end

.start_serversObject

Starts child processes.



18
19
20
# File 'lib/serverside/cluster.rb', line 18

def self.start_servers
  ports.each {|p| @@pids << fork_server(p)}
end

.stopObject

Stops child processes.



39
40
41
# File 'lib/serverside/cluster.rb', line 39

def self.stop
  stop_servers
end

.stop_serversObject

Stops child processes.



23
24
25
# File 'lib/serverside/cluster.rb', line 23

def self.stop_servers
  @@pids.each {|pid| Process.kill('TERM', pid) rescue nil}
end