From 4489111a656c296259ce6ddb9d085d695c86c774 Mon Sep 17 00:00:00 2001 From: Digimer Date: Thu, 11 Jun 2020 16:08:06 -0400 Subject: [PATCH] * Fixed a bug in Job->clear() where it was not doing it's one job right. * Updated System->generate_state_json() where when the full host name was short, it wouldn't set the short host name properly. * Fixed a bug in 'tools/anvil-manage-power' where the node wouldn't mark the reboot as complete. Resolves issue #11. Signed-off-by: Digimer --- Anvil/Tools/Job.pm | 15 +++++++-------- Anvil/Tools/System.pm | 14 +++++++++----- tools/anvil-daemon | 2 +- tools/anvil-manage-power | 6 ++++-- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Anvil/Tools/Job.pm b/Anvil/Tools/Job.pm index cbe32db9..9362d8df 100644 --- a/Anvil/Tools/Job.pm +++ b/Anvil/Tools/Job.pm @@ -108,14 +108,13 @@ sub clear return(1); } - $job_uuid = $anvil->Database->insert_or_update_jobs({ - file => $THIS_FILE, - line => __LINE__, - debug => $debug, - update_progress_only => 1, - job_uuid => $job_uuid, - job_picked_up_by => 0, - job_progress => 0, + $job_uuid = $anvil->Job->update_progress({ + debug => $debug, + file => $THIS_FILE, + line => __LINE__, + progress => 0, + message => "clear", + job_uuid => $job_uuid, }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index dc54f755..2c63526b 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -1222,7 +1222,7 @@ sub generate_state_json foreach my $host_uuid (keys %{$anvil->data->{machine}{host_uuid}}) { my $host_name = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_name}; - my $short_host_name = ($host_name =~ /^(.*?)\./)[0]; + my $short_host_name = $host_name =~ /\./ ? ($host_name =~ /^(.*?)\./)[0] : $host_name; my $host_type = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_type}; my $host_key = $anvil->data->{machine}{host_uuid}{$host_uuid}{hosts}{host_key}; my $configured = defined $anvil->data->{machine}{host_uuid}{$host_uuid}{variables}{'system::configured'} ? $anvil->data->{machine}{host_uuid}{$host_uuid}{variables}{'system::configured'} : 0; @@ -2766,7 +2766,9 @@ sub reboot_needed { # Set $anvil->Database->insert_or_update_variables({ - debug => 2, + debug => $debug, + file => $THIS_FILE, + line => __LINE__, variable_name => "reboot::needed", variable_value => "1", variable_default => "0", @@ -2774,14 +2776,15 @@ sub reboot_needed variable_section => "system", variable_source_uuid => $anvil->Get->host_uuid, variable_source_table => "hosts", - update_value_only => 1, }); } elsif ($set eq "0") { # Clear $anvil->Database->insert_or_update_variables({ - debug => 2, + debug => $debug, + file => $THIS_FILE, + line => __LINE__, variable_name => "reboot::needed", variable_value => "0", variable_default => "0", @@ -2789,7 +2792,6 @@ sub reboot_needed variable_section => "system", variable_source_uuid => $anvil->Get->host_uuid, variable_source_table => "hosts", - update_value_only => 1, }); } else @@ -2802,6 +2804,8 @@ sub reboot_needed my ($reboot_needed, $variable_uuid, $modified_date) = $anvil->Database->read_variable({ debug => $debug, + file => $THIS_FILE, + line => __LINE__, variable_name => "reboot::needed", variable_source_table => "hosts", variable_source_uuid => $anvil->Get->host_uuid, diff --git a/tools/anvil-daemon b/tools/anvil-daemon index a7484856..308d731e 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -1129,7 +1129,7 @@ sub run_jobs my $command = $job_command." --job-uuid ".$job_uuid; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0210", variables => { command => $command }}); ($anvil->data->{jobs}{handles}{$job_uuid}, my $return_code) = $anvil->System->call({ - debug => 3, + debug => 2, background => 1, stdout_file => "/tmp/anvil.job.".$job_uuid.".stdout", stderr_file => "/tmp/anvil.job.".$job_uuid.".stderr", diff --git a/tools/anvil-manage-power b/tools/anvil-manage-power index 1e4b2652..9aa7b9a9 100755 --- a/tools/anvil-manage-power +++ b/tools/anvil-manage-power @@ -66,6 +66,9 @@ if (not $anvil->data->{sys}{database}{connections}) $anvil->nice_exit({exit_code => 1}); } +# Clear the job in case a previous call failed. +$anvil->Job->clear({debug => 2, job_uuid => $anvil->data->{switches}{'job-uuid'}}) if $anvil->data->{switches}{'job-uuid'}; + # Are we being asked to reboot or power off? if ($anvil->data->{switches}{'reboot'}) { @@ -231,7 +234,6 @@ sub do_poweroff if ($job_uuid) { - $anvil->Job->clear({job_uuid => $job_uuid}); $anvil->Job->update_progress({ debug => 2, progress => $percent, @@ -242,7 +244,7 @@ sub do_poweroff # Make sure the 'reboot needed' flag is set. When 'anvil-daemon' starts, it will use this to confirm # that it is starting post-reboot and clear it. - $reboot_needed = $anvil->System->reboot_needed({set => 1}); + $reboot_needed = $anvil->System->reboot_needed({debug => 2, set => 1}); # Now do the deed. my $shell_call = $anvil->data->{path}{exe}{systemctl}." ".$task;