From 6777104398d8068507c04d52ed5701bcadbb6c1d Mon Sep 17 00:00:00 2001 From: Digimer Date: Mon, 28 Jun 2021 20:04:11 -0400 Subject: [PATCH] * Fixed a bug in anvil-daemon where, when an anvil-manage-power reboot run had triggered a reboot, anvil-daemon didn't set the job_progress to '100', causing constant reboots. Also fixed a bug where the log level was hard-set to '1' instead of '2' needed during debugging. * Updated Jobs->get_job_uuid() to accept the new 'incomplete' parameter that, when set, will look for jobs whose progress is > 1 and < 100. * Updated ScanCore-agent_startup() to take the new 'no_db_ok' parameter which returns with '0' if no DB is available and that parameter is set to '1'. * Fixed a logging bug in 'anvil-join-anvil'. Signed-off-by: Digimer --- Anvil/Tools/Job.pm | 21 +++++++++---- Anvil/Tools/Network.pm | 66 ++++++++++++++++++++++++++++++++++++++++ Anvil/Tools/ScanCore.pm | 23 +++++++++++--- tools/anvil-daemon | 10 ++++-- tools/anvil-join-anvil | 7 +++-- tools/anvil-manage-power | 4 ++- 6 files changed, 114 insertions(+), 17 deletions(-) diff --git a/Anvil/Tools/Job.pm b/Anvil/Tools/Job.pm index a237daac..fb4ad3b9 100644 --- a/Anvil/Tools/Job.pm +++ b/Anvil/Tools/Job.pm @@ -320,6 +320,10 @@ Parameters; If set, this will search for the job on a specific host. +=head3 incomplete (optional, default '0') + +If set to C<< 1 >>, any job that is incomplete (C<< job_progress < 100 >>) is searched. If set to C<< 0 >>, only job that have not started (C<< job_progress = 0 >>) are searched. + =head3 program (required) This is the program name to look for. Specifically, this string is used to search C<< job_command >> (anchored to the start of the column and a wild-card end, ie: C<< program => foo >> would find C<< foobar >> or C<< foo --bar >>). Be as specific as possible. If two or more results are found, no C<< job_uuid >> will be returned. There must be only one match for this method to work properly. @@ -333,12 +337,14 @@ sub get_job_uuid my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "Job->get_job_uuid()" }}); - my $job_uuid = ""; - my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->Get->host_uuid; - my $program = defined $parameter->{program} ? $parameter->{program} : ""; + my $job_uuid = ""; + my $host_uuid = defined $parameter->{host_uuid} ? $parameter->{host_uuid} : $anvil->Get->host_uuid; + my $incomplete = defined $parameter->{incomplete} ? $parameter->{incomplete} : 0; + my $program = defined $parameter->{program} ? $parameter->{program} : ""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - host_uuid => $host_uuid, - program => $program, + host_uuid => $host_uuid, + incomplete => $incomplete, + program => $program, }}); # Return if we don't have a program name. @@ -348,6 +354,9 @@ sub get_job_uuid return(1); } + my $say_progress = $incomplete ? "< 100" : "= 0"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { say_progress => $say_progress }}); + my $query = " SELECT job_uuid @@ -356,7 +365,7 @@ FROM WHERE job_command LIKE ".$anvil->Database->quote("%".$program."%")." AND - job_progress = 0 + job_progress ".$say_progress." AND job_host_uuid = ".$anvil->Database->quote($host_uuid)." LIMIT 1 diff --git a/Anvil/Tools/Network.pm b/Anvil/Tools/Network.pm index aa309a6d..254d98f2 100644 --- a/Anvil/Tools/Network.pm +++ b/Anvil/Tools/Network.pm @@ -2045,6 +2045,8 @@ sub get_ips $anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway} = 0 if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{default_gateway}; $anvil->data->{network}{$host}{interface}{$in_iface}{gateway} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{gateway}; $anvil->data->{network}{$host}{interface}{$in_iface}{dns} = "" if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{dns}; + $anvil->data->{network}{$host}{interface}{$in_iface}{tx_bytes} = 0 if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{tx_bytes}; + $anvil->data->{network}{$host}{interface}{$in_iface}{rx_bytes} = 0 if not defined $anvil->data->{network}{$host}{interface}{$in_iface}{rx_bytes}; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { "network::${host}::interface::${in_iface}::ip" => $anvil->data->{network}{$host}{interface}{$in_iface}{ip}, "network::${host}::interface::${in_iface}::subnet_mask" => $anvil->data->{network}{$host}{interface}{$in_iface}{subnet_mask}, @@ -2054,6 +2056,70 @@ sub get_ips "network::${host}::interface::${in_iface}::gateway" => $anvil->data->{network}{$host}{interface}{$in_iface}{gateway}, "network::${host}::interface::${in_iface}::dns" => $anvil->data->{network}{$host}{interface}{$in_iface}{dns}, }}); + + if ($in_iface ne "lo") + { + # Read the read and write bytes. + my $read_bytes = 0; + my $write_bytes = 0; + my $shell_call = " +if [ -e '/sys/class/net/".$in_iface."/statistics/rx_bytes' ]; +then + echo -n 'rx:'; + cat /sys/class/net/".$in_iface."/statistics/rx_bytes; + echo -n 'tx:'; + cat /sys/class/net/".$in_iface."/statistics/tx_bytes; +else + echo 'rx:0'; + echo 'tx:0'; +fi"; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }}); + my $transmit_sizes = ""; + if ($is_local) + { + # Local call. + ($transmit_sizes, my $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:transmit_sizes' => $transmit_sizes, + 's2:return_code' => $return_code, + }}); + } + else + { + # Remote call + ($transmit_sizes, my $error, my $return_code) = $anvil->Remote->call({ + debug => $debug, + shell_call => $shell_call, + target => $target, + user => $remote_user, + password => $password, + remote_user => $remote_user, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + 's1:transmit_sizes' => $transmit_sizes, + 's2:error' => $error, + 's3:return_code' => $return_code, + }}); + } + foreach my $line (split/\n/, $transmit_sizes) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { line => $line }}); + if ($line =~ /rx:(\d+)/) + { + $anvil->data->{network}{$host}{interface}{$in_iface}{rx_bytes} = $1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "network::${host}::interface::${in_iface}::rx_bytes" => $anvil->data->{network}{$host}{interface}{$in_iface}{rx_bytes}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{network}{$host}{interface}{$in_iface}{rx_bytes}}).")", + }}); + } + if ($line =~ /tx:(\d+)/) + { + $anvil->data->{network}{$host}{interface}{$in_iface}{tx_bytes} = $1; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + "network::${host}::interface::${in_iface}::tx_bytes" => $anvil->data->{network}{$host}{interface}{$in_iface}{tx_bytes}." (".$anvil->Convert->bytes_to_human_readable({'bytes' => $anvil->data->{network}{$host}{interface}{$in_iface}{tx_bytes}}).")", + }}); + } + } + } } next if not $in_iface; if ($in_iface eq "lo") diff --git a/Anvil/Tools/ScanCore.pm b/Anvil/Tools/ScanCore.pm index b22cc3c3..d9ff2fdd 100644 --- a/Anvil/Tools/ScanCore.pm +++ b/Anvil/Tools/ScanCore.pm @@ -100,6 +100,10 @@ Parameters; This is the name of the scan agent. Usually this can be set as C<< $THIS_FILE >>. +=head3 no_db_ok (optional, default 0) + +If set to C<< 1 >>, if no database connections are available but otherwise the startup is OK, C<< 0 >> (no problem) is returned. + =head3 tables (required) This is an array reference of database tables to check when resync'ing. It is important that the tables are sorted in the order they need to be resync'ed in. (tables with primary keys before their foreign key tables). @@ -113,11 +117,13 @@ sub agent_startup my $debug = defined $parameter->{debug} ? $parameter->{debug} : 3; $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "ScanCore->agent_startup()" }}); - my $agent = defined $parameter->{agent} ? $parameter->{agent} : ""; - my $tables = defined $parameter->{tables} ? $parameter->{tables} : ""; + my $agent = defined $parameter->{agent} ? $parameter->{agent} : ""; + my $no_db_ok = defined $parameter->{no_db_ok} ? $parameter->{no_db_ok} : ""; + my $tables = defined $parameter->{tables} ? $parameter->{tables} : ""; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { - agent => $agent, - tables => $tables, + agent => $agent, + no_db_ok => $no_db_ok, + tables => $tables, }}); # Setting this will prepend messages coming grom the agent with the agent's name @@ -160,7 +166,14 @@ sub agent_startup { # No databases, exit. $anvil->Log->entry({source => $agent, line => __LINE__, 'print' => 1, level => 0, secure => 0, key => "error_0003"}); - return(1); + if ($no_db_ok) + { + return(0); + } + else + { + return(1); + } } my $table_count = @{$tables}; diff --git a/tools/anvil-daemon b/tools/anvil-daemon index bff5b879..0139962c 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -144,7 +144,7 @@ $anvil->data->{switches}{'no-start'} = 0; $anvil->data->{switches}{'startup-only'} = 0; $anvil->Get->switches; -$anvil->Log->level({set => 1}); +$anvil->Log->level({set => 2}); $anvil->Log->secure({set => 1}); $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0115", variables => { program => $THIS_FILE }}); @@ -866,7 +866,7 @@ sub boot_time_tasks # If the uptime is less than ten minutes, clear the reboot flag. my $uptime = $anvil->Get->uptime; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { uptime => $uptime }}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { uptime => $uptime }}); # Now find out if a reboot is listed as needed and when it was last changed. my $reboot_needed = 0; @@ -921,7 +921,11 @@ AND $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { reboot_needed => $reboot_needed }}); # Check to see if there was a reboot job in progress. If so, finish it off. - my $job_uuid = $anvil->Job->get_job_uuid({debug => 2, program => "anvil-manage-power"}); + my $job_uuid = $anvil->Job->get_job_uuid({ + debug => 2, + program => "anvil-manage-power", + incomplete => 1, + }); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { job_uuid => $job_uuid }}); if ($job_uuid) diff --git a/tools/anvil-join-anvil b/tools/anvil-join-anvil index fe868e64..11ddcda2 100755 --- a/tools/anvil-join-anvil +++ b/tools/anvil-join-anvil @@ -216,11 +216,14 @@ sub configure_pacemaker ($return_code) = $anvil->System->disable_daemon({daemon => "ksm.service"}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { return_code => $return_code }}); $return_code = undef; + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "job_0095", variables => { daemon => "ksm.service" }}); + update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0095,!!daemon!ksm.service!!"); + ($return_code) = $anvil->System->stop_daemon({daemon => "ksmtuned.service"}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => { return_code => $return_code }}); $return_code = undef; - update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0095,!!daemon!ksm.service!!"); - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "job_0095", variables => { daemon => "drbd.service" }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, key => "job_0095", variables => { daemon => "ksmtuned.service" }}); + update_progress($anvil, ($anvil->data->{job}{progress} += 2), "job_0095,!!daemon!ksmtuned.service!!"); # If there is no corosync.conf, see if the peer has it. If so, copy it. If not, we'll initialize the # cluster shortly. diff --git a/tools/anvil-manage-power b/tools/anvil-manage-power index e896c059..4b4b9934 100755 --- a/tools/anvil-manage-power +++ b/tools/anvil-manage-power @@ -215,7 +215,9 @@ sub do_poweroff $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, secure => 0, key => $say_task}); sleep $difference; - $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0227", variables => { task => $task eq "poweroff" ? "#!string!log_0225!#" : "#!string!log_0226!#" }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure => 0, key => "log_0227", variables => { + task => $task eq "poweroff" ? "#!string!log_0225!#" : "#!string!log_0226!#", + }}); } # If I don't have a job_uuid, try to find one.