hostname.rb revision 13fc9a105393bc799a26cdba6f7e759435e3ec23
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch# Compute hostname and port from the hostname in the Settings.
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen# If no hostname is specified, read the hostname from the OS.
687d1dee0e92229232aa8be416897b640df67d07Timo Sirainen hostname = Settings.hostname.split(':').first if Settings.hostname
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen if hostname == 'localhost' || (hostname && hostname.include?('.'))
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen Addrinfo.tcp(Socket.gethostname, 0).getnameinfo.first
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen Could not automatically determine the hostname:
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen #{e.class}: #{e.message}
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen Please set the hostname manually in the configuration
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen or consult the documentation of `gethostname`:
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * http://ruby-doc.org/stdlib/libdoc/socket/rdoc/Socket.html#method-c-gethostname
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen * man gethostname
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen * http://linux.die.net/man/2/gethostname
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen $stderr.puts message
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen def self.port
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen Settings.hostname.split(':').last if Settings.hostname.include?(':')
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen def self.url_authority(scheme: 'http')
2de709376eddc50ec5fa470358bb57cf0a87bb1fTimo Sirainen port = Ontohub::Application.config.port
5bbce06405dd5fc0d67411e48856953785f109f5Timo Sirainen port = ":#{port}" if port
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen "#{scheme}://#{Ontohub::Application.config.fqdn}#{port}"
a24665de9d5c773115a5918e60ed587aafe67d5cTimo SirainenOntohub::Application.config.fqdn = Hostname.fqdn
a24665de9d5c773115a5918e60ed587aafe67d5cTimo SirainenOntohub::Application.config.port = Hostname.port
a24665de9d5c773115a5918e60ed587aafe67d5cTimo SirainenOntohub::Application.routes.default_url_options[:host] = Hostname.fqdn
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainenif Hostname.port
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen Ontohub::Application.routes.default_url_options[:host] << ":#{Hostname.port}"