module Idlc::Build::Httpd
Public Class Methods
private_ip()
click to toggle source
# File lib/idlc-sdk-build/httpd.rb, line 5 def private_ip Socket.ip_address_list.detect(&:ipv4_private?).ip_address end
start(root_dir, sleep_time = 3)
click to toggle source
# File lib/idlc-sdk-build/httpd.rb, line 9 def start(root_dir, sleep_time = 3) httpd = server(root_dir) pid = Process.fork if pid.nil? # In child exec(( trap('INT') { httpd.shutdown } httpd.start # ignore the nil excpetion here, this happens when the child process exits )) rescue nil else # In parent Process.detach(pid) end sleep sleep_time # Return process id pid end
stop(pid)
click to toggle source
# File lib/idlc-sdk-build/httpd.rb, line 31 def stop(pid) Process.kill('INT', pid) unless pid.nil? end
Private Class Methods
server(root)
click to toggle source
# File lib/idlc-sdk-build/httpd.rb, line 37 def server(root) # get a random port number port = Random.rand(49_152...65_535) ENV['HTTPD_PORT'] = port.to_s WEBrick::HTTPServer.new( Port: port, DocumentRoot: root ) end