Class: Upman::Server::Socket

Inherits:
Object
  • Object
show all
Includes:
Utils::Dynload, Utils::Helper, WEBrick
Defined in:
lib/upman/server/socket.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Dynload

#dynload

Methods included from Utils::Helper

#fail, #info, #success, #warn

Constructor Details

#initializeSocket

Returns a new instance of Socket.



16
17
18
19
# File 'lib/upman/server/socket.rb', line 16

def initialize
  @config = ::Upman::Core::Config.daemon

end

Instance Attribute Details

#serverObject (readonly)

Returns the value of attribute server.



14
15
16
# File 'lib/upman/server/socket.rb', line 14

def server
  @server
end

Instance Method Details

#run!Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/upman/server/socket.rb', line 21

def run!

  server = HTTPServer.new(
      BindAddress: @config[:listen],
      :Port => @config[:port],
      :SSLEnable => @config[:ssl],
      :debugger => false,
      :daemonize => true,
      :SSLPrivateKey => OpenSSL::PKey::RSA.new(
          File.open(@config[:key]).read),
      :SSLCertificate => OpenSSL::X509::Certificate.new(
          File.open(@config[:cert]).read),
      :SSLCertName => [["CN", WEBrick::Utils::getservername]],
      Logger: WEBrick::Log.new("/dev/null"),
      AccessLog: [],
  )

  _register_extensions(server)

  protocol = @config[:ssl] ? 'https://' : 'http://'
  info "Starting listener on #{protocol}#{@config[:listen]}:#{@config[:port]}"
  server.start

end