class RabbotWebServer::ServerHandle
Attributes
Public Class Methods
Source
# File lib/rabbot_web_server.rb, line 31 def initialize(web) @web = web @mutex = Mutex.new @server = nil @thread = nil @port = web[:port] end
Public Instance Methods
Source
# File lib/rabbot_web_server.rb, line 56 def running? @mutex.synchronize { @thread&.alive? } end
Source
# File lib/rabbot_web_server.rb, line 39 def start @mutex.synchronize do return if @thread&.alive? @server = WEBrick::HTTPServer.new( BindAddress: @web[:bind], Port: @web[:port], DocumentRoot: @web[:root], Logger: WEBrick::Log.new($stderr, WEBrick::Log::WARN), AccessLog: [] ) @thread = Thread.new { @server.start } @port = @server.config[:Port] end self end
Source
# File lib/rabbot_web_server.rb, line 60 def stop @mutex.synchronize do return unless @server @server.shutdown @thread&.join(5) @server = nil @thread = nil end end