Class: Dnsync::HttpStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/dnsync/http_status.rb

Instance Method Summary collapse

Constructor Details

#initialize(port, updater) ⇒ HttpStatus

Returns a new instance of HttpStatus.



5
6
7
8
# File 'lib/dnsync/http_status.rb', line 5

def initialize(port, updater)
  @port    = port
  @updater = updater
end

Instance Method Details

#handler(request, response) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/dnsync/http_status.rb', line 44

def handler(request, response)
  health_problems = @updater.health_problems

  if health_problems.blank?
    response.status = 200
    response.body   = "OK\n"
  else
    response.status = 500
    response.body = health_problems + "\n"
  end
end

#joinObject



36
37
38
39
40
41
42
# File 'lib/dnsync/http_status.rb', line 36

def join
  if @thread
    @thread.join
  end

  self
end

#startObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dnsync/http_status.rb', line 10

def start
  return if @server || @thread

  logger = WEBrick::Log.new
  logger.level = WEBrick::Log::WARN

  @server = WEBrick::HTTPServer.new(:Port => @port,
    :Logger => logger, :AccessLog => [])
  @server.mount_proc("/status", &method(:handler))

  @thread = Thread.new do
    Thread.current.abort_on_exception = true
    @server.start
  end

  self
end

#stopObject



28
29
30
31
32
33
34
# File 'lib/dnsync/http_status.rb', line 28

def stop
  if @server
    @server.stop
  end

  self
end