Class: Subserver::Health

Inherits:
Object
  • Object
show all
Defined in:
lib/subserver/health.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHealth

Returns a new instance of Health.



8
9
10
# File 'lib/subserver/health.rb', line 8

def initialize
  @server = TCPServer.new Subserver.options[:health_port] || 4081
end

Instance Attribute Details

#serverObject

Returns the value of attribute server.



6
7
8
# File 'lib/subserver/health.rb', line 6

def server
  @server
end

Instance Method Details

#loggerObject



34
35
36
# File 'lib/subserver/health.rb', line 34

def logger
  Subserver.logger
end

#startObject



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

def start
  begin
    logger.debug "Health check avalible on port #{@server.addr[1]}"
    while session = @server.accept
      request = session.gets

      session.print "HTTP/1.1 200\r\n" # 1
      session.print "Content-Type: text/html\r\n" # 2
      session.print "\r\n" # 3
      session.print "Subserver Online" #4
      session.close
    end
  rescue Errno::ECONNRESET, Errno::EPIPE => e
    puts e.message
    retry
  end
end

#stopObject



30
31
32
# File 'lib/subserver/health.rb', line 30

def stop
  @server.close
end