Class: Procodile::ControlServer

Inherits:
Object
  • Object
show all
Defined in:
lib/procodile/control_server.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(supervisor) ⇒ ControlServer

Returns a new instance of ControlServer.



14
15
16
# File 'lib/procodile/control_server.rb', line 14

def initialize(supervisor)
  @supervisor = supervisor
end

Class Method Details

.start(supervisor) ⇒ Object



7
8
9
10
11
12
# File 'lib/procodile/control_server.rb', line 7

def self.start(supervisor)
  Thread.new do
    socket = ControlServer.new(supervisor)
    socket.listen
  end
end

Instance Method Details

#listenObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/procodile/control_server.rb', line 18

def listen
  socket = UNIXServer.new(@supervisor.config.sock_path)
  Procodile.log nil, 'control', "Listening at #{@supervisor.config.sock_path}"
  loop do
    client = socket.accept
    session = ControlSession.new(@supervisor, client)
    while line = client.gets
      if response = session.receive_data(line.strip)
        client.puts response
      end
    end
    client.close
  end
ensure
  FileUtils.rm_f(@supervisor.config.sock_path)
end