hostname.rb revision a446fc1729ca15222cd35f657ebe75152ac5a39c
1516N/A# Compute hostname and port from the hostname in the Settings.
941N/A# If no hostname is specified, read the hostname from the OS.
941N/Amodule Hostname
941N/A def self.fqdn
941N/A hostname = Settings.hostname.split(':').first if Settings.hostname
941N/A if hostname == 'localhost' || (hostname && hostname.include?('.'))
941N/A hostname
941N/A else
941N/A begin
941N/A Addrinfo.tcp(Socket.gethostname, 0).getnameinfo.first
941N/A rescue ::SocketError => e
941N/A message = <<-MSG.strip_heredoc
941N/A Could not automatically determine the hostname:
941N/A #{e.class}: #{e.message}
941N/A
941N/A Please set the hostname manually in the configuration
941N/A or consult the documentation of `gethostname`:
941N/A * http://ruby-doc.org/stdlib/libdoc/socket/rdoc/Socket.html#method-c-gethostname
941N/A * man gethostname
941N/A * http://linux.die.net/man/2/gethostname
941N/A MSG
941N/A $stderr.puts message
3158N/A exit
941N/A end
941N/A end
941N/A end
941N/A
1715N/A def self.port
941N/A Settings.hostname.split(':').last if Settings.hostname
1230N/A end
941N/A
941N/A def self.url_authority(scheme: 'http')
1230N/A port = Ontohub::Application.config.port
941N/A port = ":#{port}" if port
1230N/A "#{scheme}://#{Ontohub::Application.config.fqdn}#{port}/"
1291N/A end
941N/Aend
941N/A
941N/AOntohub::Application.config.fqdn = Hostname.fqdn
941N/AOntohub::Application.config.port = Hostname.port
941N/A