Skip to content

Commit

Permalink
configure - adding hostname checks
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap committed Dec 5, 2011
1 parent 24b8628 commit d03ffb7
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions puppet/bin/katello-configure
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'optparse'
require 'fcntl'
require 'fileutils'
require 'socket'

$stdout.sync = true

Expand All @@ -20,6 +21,7 @@ ERROR_CODES = {
:answer_parsing_error => 4,
:answer_unknown_option => 5,
:error_executing_puppet => 6,
:hostname_error => 7,
:unknown => 127,
}

Expand Down Expand Up @@ -201,6 +203,23 @@ if show_resulting_answer_file
exit
end

# Prints a warning if FQDN is not set, returns error when
# localhost or hostname cannot be resolved (/etc/hosts entry is missing).
def check_hostname
hostname = Socket.gethostname
Socket.gethostbyname hostname
Socket.gethostbyname 'localhost'
$stderr.puts "WARNING: FQDN is not set!" unless hostname.index '.'
rescue SocketError => e
puts "Error"
$stderr.puts "Unable to resolve '#{hostname}' or 'localhost'. Check your DNS and /etc/hosts settings."
exit_with :hostname_error
end

# perform check-up
check_hostname

# start configuring
puts 'Starting Katello configuration'

orig_umask = File.umask(077)
Expand Down

0 comments on commit d03ffb7

Please sign in to comment.