From 66c82e5e22cf2fd33db67b52ee18daaec10cef60 Mon Sep 17 00:00:00 2001 From: digimer Date: Sun, 23 Jul 2023 21:40:49 -0400 Subject: [PATCH] * Fixed a bug in anvil-update-system where updating a single package with --reboot wouldn't request a reboot. Finished reworking it so that a check is made to see if the kernel or DRBD kmod will be updated and, if so, removes the kmod-drbd RPMs prior to doing the update (as opposed to the sloppier check-on-error method). * Fixed a bug in System->reboot_needed() where the cache file path had a typo in the hash key. * Updated anvil-daemon to use the full path to dnf when determining if a dnf process was running. Signed-off-by: digimer --- Anvil/Tools/System.pm | 2 +- share/words.xml | 1 + tools/anvil-daemon | 2 +- tools/anvil-update-system | 81 +++++++++++++++++++++------------------ 4 files changed, 47 insertions(+), 39 deletions(-) diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index 7f41a3ab..a0732d20 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -4460,7 +4460,7 @@ sub reboot_needed my $set = defined $parameter->{set} ? $parameter->{set} : ""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { set => $set }}); - my $cache_file = $anvil->data->{paths}{data}{reboot_cache}; + my $cache_file = $anvil->data->{path}{data}{reboot_cache}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { cache_file => $cache_file }}); if (($set) or ($set eq "0")) { diff --git a/share/words.xml b/share/words.xml index 02a8b0f6..ab528f3f 100644 --- a/share/words.xml +++ b/share/words.xml @@ -2408,6 +2408,7 @@ The file: [#!variable!file!#] needs to be updated. The difference is: I was about to start: [#!variable!command!#] with the job UUID: [#!variable!this_job_uuid!#]. However, another job using the same command with the job UUID: [#!variable!other_job_uuid!#]. To avoid race conditions, only one process with a given command is run at the same time. The job with the command: [#!variable!command!#] and job UUID: [#!variable!job_uuid!#] is restarting. Will run without connecting to the databases. Some features will be unavailable. + A cached request to reboot this host was found (likely from a --no-db update). Registering a job to reboot now! The host name: [#!variable!target!#] does not resolve to an IP address. diff --git a/tools/anvil-daemon b/tools/anvil-daemon index 4d31ae49..6b3c282a 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -266,7 +266,7 @@ sub wait_on_dnf }}); while ($waiting) { - my $pids = $anvil->System->pids({program_name => "dnf"}); + my $pids = $anvil->System->pids({program_name => $anvil->data->{path}{exe}{dnf}}); my $dnf_instances = @{$pids}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { dnf_instances => $dnf_instances }}); diff --git a/tools/anvil-update-system b/tools/anvil-update-system index a7e320c0..c82d358f 100755 --- a/tools/anvil-update-system +++ b/tools/anvil-update-system @@ -191,6 +191,9 @@ WHERE # Register a job to reboot. update_progress($anvil, 98, "message_0318"); + # Record that we're going to reboot now. + update_progress($anvil, 100, "message_0317"); + if ($anvil->data->{sys}{database}{connections}) { my ($job_uuid) = $anvil->Database->insert_or_update_jobs({ @@ -202,12 +205,16 @@ WHERE job_title => "job_0009", job_description => "job_0006", job_progress => 0, + job_status => "anvil_startup", }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); + + # If we got a job UUID, unlink the cache file. + if (-e $anvil->data->{path}{data}{reboot_cache}) + { + unlink $anvil->data->{path}{data}{reboot_cache}; + } } - - # Record that we're going to reboot now. - update_progress($anvil, 100, "message_0317"); } else { @@ -242,6 +249,12 @@ sub update_progress "jobs::job_uuid" => $anvil->data->{jobs}{job_uuid}, }}); + if ($progress > 100) + { + $progress = 100; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { progress => $progress }}); + } + if ($anvil->data->{jobs}{job_uuid}) { $anvil->Job->update_progress({ @@ -260,24 +273,21 @@ sub update_progress sub run_os_update { my ($anvil, $progress) = @_; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { - try => $try, - progress => $progress, - }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { progress => $progress }}); # This needs to be set to avoid warnings when called without a job-uuid. $anvil->data->{sys}{last_update} = 0; # Make sure that, if we're a node, we're out of the cluster. my $host_type = $anvil->Get->host_type(); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { host_type => $host_type }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { host_type => $host_type }}); if ($host_type eq "node") { # Call anvil-safe-stop update_progress($anvil, $progress++, "message_0314"); - my $problem = $anvil->Cluster->parse_cib({debug => 3}); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { problem => $problem }}); + my $problem = $anvil->Cluster->parse_cib(); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { problem => $problem }}); if (not $problem) { # Call anvil-safe-stop @@ -334,15 +344,14 @@ WHERE } # Before we start, do we need to remove our locally build DRBD kernel modules? + my $package_changes = 0; my $remove_drbd_kmod = 0; my $shell_call = $anvil->data->{path}{exe}{dnf}." check-update"; open (my $file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); while(<$file_handle>) { chomp; - my $line = $_; - $output .= $line."\n"; - $line = $anvil->Words->clean_spaces({string => $line}); + my $line = $anvil->Words->clean_spaces({string => $_}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); if (($line =~ /kmod-drbd/) or ($line =~ /kernel/)) @@ -359,6 +368,7 @@ WHERE # So, shall we? if ($remove_drbd_kmod) { + # Yes, remove update_progress($anvil, $progress++, "message_0320"); my $versions_to_remove = ""; my $shell_call = $anvil->data->{path}{exe}{dnf}." list installed"; @@ -375,7 +385,11 @@ WHERE if ($line =~ /(kmod-drbd-\d+.*?)\s/) { $versions_to_remove .= $1." "; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { versions_to_remove => $versions_to_remove }}); + $package_changes++; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + versions_to_remove => $versions_to_remove, + package_changes => $package_changes, + }}); } } @@ -384,26 +398,17 @@ WHERE $shell_call = $anvil->data->{path}{exe}{dnf}." -y remove ".$versions_to_remove; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); - ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { - output => $output, - return_code => $return_code, - }}); - -# # Now install the new packages. -# update_progress($anvil, $progress++, "message_0322"); -# $shell_call = $anvil->data->{path}{exe}{dnf}." -y install kmod-drbd"; -# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); -# -# ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); -# $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { -# output => $output, -# return_code => $return_code, -# }}); + open ($file_handle, $shell_call." 2>&1 |") or $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, secure => 0, priority => "err", key => "log_0014", variables => { shell_call => $shell_call, error => $! }}); + while(<$file_handle>) + { + chomp; + my $line = $anvil->Words->clean_spaces({string => $_}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { line => $line }}); + } + close $file_handle; } # NOTE: We run this directly to better monitor progress and update the progress. - my $package_changes = 0; my $transaction_shown = 0; my $success = 0; my $to_update = 0; @@ -434,7 +439,7 @@ WHERE { # Update done, verifying now. $verifying = 1; - update_progress($anvil, $progress, "message_0038"); + update_progress($anvil, $progress++, "message_0038"); } if ($line =~ /Running transaction/i) @@ -442,7 +447,7 @@ WHERE # Done downloading if (not $transaction_shown) { - update_progress($anvil, $progress, "message_0037"); + update_progress($anvil, $progress++, "message_0037"); $transaction_shown = 1; } } @@ -458,7 +463,7 @@ WHERE } } - if ($line =~ / (\d+) Packages$/i) + if (($line =~ / (\d+) Packages$/i) or ($line =~ / (\d+) Package$/i)) { my $counted_lines = $1; $package_changes = $counted_lines; @@ -476,7 +481,7 @@ WHERE $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { update_size => $update_size }}); # Ready to install, update to 5%. The next step will count up to 95%. - update_progress($anvil, $progress, "message_0035,!!size!$update_size!!"); + update_progress($anvil, $progress++, "message_0035,!!size!$update_size!!"); # The total (reliable) count of events is (to_update * 3), counting '(x/y): ' # (download), 'Upgrading '/'Installing ' and 'Verifying '. We ignore the scriplet @@ -539,8 +544,10 @@ WHERE close $file_handle; # Reload daemons to pick up any changed systemctl daemons. - my ($systemctl_output, $return_code) = $anvil->System->call({debug => 3, shell_call => $anvil->data->{path}{exe}{systemctl}." daemon-reload", source => $THIS_FILE, line => __LINE__}); - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { systemctl_output => $systemctl_output, return_code => $return_code }}); + $shell_call = $anvil->data->{path}{exe}{systemctl}." daemon-reload"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }}); + my ($systemctl_output, $return_code) = $anvil->System->call({shell_call => $shell_call}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { systemctl_output => $systemctl_output, return_code => $return_code }}); ### See if the kernel has been updated. # Get the newest installed kernel