diff --git a/Anvil/Tools.pm b/Anvil/Tools.pm index 5862c090..ee8de4be 100644 --- a/Anvil/Tools.pm +++ b/Anvil/Tools.pm @@ -1210,6 +1210,7 @@ sub _set_paths 'grep' => "/usr/bin/grep", groupadd => "/usr/sbin/groupadd", head => "/usr/bin/head", + hostname => "/usr/bin/hostname", hostnamectl => "/usr/bin/hostnamectl", hpacucli => "/usr/sbin/hpacucli", htpasswd => "/usr/bin/htpasswd", diff --git a/Anvil/Tools/Database.pm b/Anvil/Tools/Database.pm index a7002d58..3e0903b2 100644 --- a/Anvil/Tools/Database.pm +++ b/Anvil/Tools/Database.pm @@ -9606,9 +9606,9 @@ sub insert_or_update_hosts my $line = defined $parameter->{line} ? $parameter->{line} : ""; my $host_ipmi = defined $parameter->{host_ipmi} ? $parameter->{host_ipmi} : ""; my $host_key = defined $parameter->{host_key} ? $parameter->{host_key} : ""; - my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : $anvil->Get->host_name; - my $host_type = defined $parameter->{host_type} ? $parameter->{host_type} : $anvil->Get->host_type; - my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->Get->host_uuid; + my $host_name = defined $parameter->{host_name} ? $parameter->{host_name} : ""; + my $host_type = defined $parameter->{host_type} ? $parameter->{host_type} : ""; + my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : ""; my $host_status = defined $parameter->{host_status} ? $parameter->{host_status} : "no_change"; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { uuid => $uuid, @@ -9624,15 +9624,34 @@ sub insert_or_update_hosts if (not $host_name) { - # Throw an error and exit. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_hosts()", parameter => "host_name" }}); - return(""); + # Can we get it? + $host_name = $anvil->Get->host_name({debug => $debug}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_name => $host_name }}); + + if (not $host_name) + { + # Throw an error and exit. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_hosts()", parameter => "host_name" }}); + return(""); + } + } + if (not $host_type) + { + $host_type = $anvil->Get->host_type({debug => $debug}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_type => $host_type }}); } if (not $host_uuid) { - # Throw an error and exit. - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_hosts()", parameter => "host_uuid" }}); - return(""); + # Can we get it? + $host_uuid = $anvil->Get->host_uuid({debug => $debug}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { host_uuid => $host_uuid }}); + + if (not $host_uuid) + { + # Throw an error and exit. + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "err", key => "log_0020", variables => { method => "Database->insert_or_update_hosts()", parameter => "host_uuid" }}); + return(""); + } } # If we're looking at ourselves and we don't have the host_key, read it in. diff --git a/Anvil/Tools/Get.pm b/Anvil/Tools/Get.pm index 29e8204a..39c4ccfa 100644 --- a/Anvil/Tools/Get.pm +++ b/Anvil/Tools/Get.pm @@ -1513,10 +1513,29 @@ sub host_name { # Failed to read the file, too. What the hell? Exit out. print "Failed to query the hostname using 'hostnamectl --static' and failed to read the content of: [".$anvil->data->{path}{configs}{hostname}."]. Something is very wrong, exiting.\n"; + $anvil->nice_exit({exit_code => 1}); } } else { + # Did we get a real answer? If it's "unet", the string will be emtpy. + if (not $host_name) + { + # Try seeing if there is a transient hostname. + ($host_name, my $return_code) = $anvil->System->call({debug => 9999, shell_call => $anvil->data->{path}{exe}{hostnamectl}." --transient"}); + if (not $host_name) + { + # OK, can we get it from the 'hostname' command? + ($host_name, my $return_code) = $anvil->System->call({debug => 9999, shell_call => $anvil->data->{path}{exe}{hostname}}); + if (not $host_name) + { + # Failed to find the hostname at all. + print "Failed to query the hostname using 'hostnamectl --static', 'hostnamectl --transient' or 'hostname'. Something is very wrong, exiting.\n"; + $anvil->nice_exit({exit_code => 1}); + } + } + } + # Cache the answer $anvil->data->{sys}{host_name} = $host_name; } diff --git a/tools/anvil-check-memory b/tools/anvil-check-memory index 971ade0a..acf0bb72 100755 --- a/tools/anvil-check-memory +++ b/tools/anvil-check-memory @@ -84,7 +84,7 @@ foreach my $pid (sort {$a cmp $b} @{$anvil->data->{sys}{pids}}) { my $size = $1; my $type = $2; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { type => $type, size => $size, }}); @@ -94,10 +94,10 @@ foreach my $pid (sort {$a cmp $b} @{$anvil->data->{sys}{pids}}) # This uses 'kB' for 'KiB' >_> $type = lc($type); $type =~ s/b$/ib/ if $type !~ /ib$/; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { type => $type }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { type => $type }}); my $size_in_bytes = $anvil->Convert->human_readable_to_bytes({size => $size, type => $type, base2 => 1}); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { size_in_bytes => $anvil->Convert->add_commas({number => $size_in_bytes})." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $size_in_bytes}).")", }}); diff --git a/tools/anvil-version-changes b/tools/anvil-version-changes index c49176e9..d1932520 100755 --- a/tools/anvil-version-changes +++ b/tools/anvil-version-changes @@ -63,12 +63,12 @@ sub striker_checks { my ($anvil) = @_; + # This checks to make sure that the new 'file_locations' -> 'file_location_ready' column exists. + update_file_location_ready($anvil); + # This checks to make sure that the new dr_links table exists, and that existing anvil_dr1_host_uuid # entries are copied. update_dr_links($anvil); - - # This checks to make sure that the new 'file_locations' -> 'file_location_ready' column exists. - update_file_location_ready($anvil); # This replaces anvil_uuid with host_uuid to support more granular location info to support the new # multi-target DR system