Class: Explorer::Servers

Inherits:
Object
  • Object
show all
Defined in:
lib/explorer/servers.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Servers

Returns a new instance of Servers.



5
6
7
8
9
10
# File 'lib/explorer/servers.rb', line 5

def initialize options={}
  @dns_port = options.fetch(:dns_port) { 23400 }
  @http_port = options.fetch(:http_port) { 23401 }
  @https_port = options.fetch(:https_port) { 23402 }
  @ipc_file = options.fetch(:ipc_file) { '/tmp/explorer_ipc' }
end

Instance Method Details

#loadObject



29
30
31
32
# File 'lib/explorer/servers.rb', line 29

def load
  Explorer.hostmap.load File.join(Explorer::CONFIGDIR, 'hostmap.yaml')
  Explorer.process_manager.load File.join(Explorer::CONFIGDIR, 'process.yaml')
end

#runObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/explorer/servers.rb', line 12

def run
  # Setup trap
  read, write = IO.pipe
  trap(:INT) { write.puts }

  # Start servers
  run!

  # Load configuration
  load

  IO.select([read]) # Wait for trap

  # Cleanup
  terminate
end

#run!Object



40
41
42
43
44
45
46
47
48
# File 'lib/explorer/servers.rb', line 40

def run!
  Celluloid.logger = Explorer.log_watcher.logger
  @group = Celluloid::SupervisionGroup.new do |group|
    group.supervise_as :dns, Server::DNS, @dns_port
    group.supervise_as :http, Server::HTTP, @http_port
    group.supervise_as :https, Server::HTTPS, @https_port
    group.supervise_as :ipc, Server::IPC, @ipc_file
  end
end

#terminateObject

Do I need this?



35
36
37
38
# File 'lib/explorer/servers.rb', line 35

def terminate
  @group.terminate if @group
  Explorer.terminate
end