Sha256: 57c408b37797649adde6f59ce5bfa3f80d56ec9006021f0a60717f427dec77e1
Contents?: true
Size: 1.65 KB
Versions: 10
Compression:
Stored size: 1.65 KB
Contents
class Rad::Http::RackAdapter SERVERS = %w{thin mongrel webrick} # class Callback # def initialize app; end # def self.call env; Rad::Adapter.call env end # end # class << self inject logger: :logger def initialize_rack builder = nil, &block @rack_configurations ||= [] if block raise "provide configuration block!" unless block @rack_configurations << block else if @rack_configurations.empty? raise "Common App not defined! Use profiles (like rad/profiles/web), define it by yourself or use your own configuration!" end @rack_configurations.each{|conf| conf.call builder} end end def run app, host, port handler = detect_rack_handler handler_name = handler.name.gsub(/.*::/, '') logger.info "RAD http server started on #{host}:#{port}" unless rad.test? # unless handler_name =~/cgi/i handler.run app, Host: host, Port: port do |server| [:INT, :TERM].each {|sig| trap(sig){quit!(server, handler_name)}} end rescue Errno::EADDRINUSE => e logger.error "RAD port #{port} taken!" end def quit!(server, handler_name) ## Use thins' hard #stop! if available, otherwise just #stop server.respond_to?(:stop!) ? server.stop! : server.stop puts "\nRad stopped" unless handler_name =~/cgi/i end protected def detect_rack_handler return Rack::Handler.get('thin') SERVERS.each do |server_name| begin return Rack::Handler.get(server_name.downcase) rescue LoadError rescue NameError end end fail " Server handler (#{SERVERS.join(', ')}) not found." end # end end
Version data entries
10 entries across 10 versions & 1 rubygems