From ab9b00a2f77656714e065d413f9d561b6b2c82d2 Mon Sep 17 00:00:00 2001 From: Digimer Date: Tue, 21 Jun 2022 22:25:07 -0400 Subject: [PATCH] * Updated anvil-daemon, in its daily checks, to disable ksm and ksmtuned daemons. * Updated scan-drbd to purge peer records that no longer have corresponding LVM data. * Updated System->{en,dis}able-service to take the 'now' paramter which, when passed, causes the action to take immediate effect. Signed-off-by: Digimer --- Anvil/Tools/System.pm | 36 ++++++++++++++++++++++--- notes | 1 + scancore-agents/scan-drbd/scan-drbd | 35 +++++++++++++++++++++++- scancore-agents/scan-drbd/scan-drbd.xml | 1 + share/words.xml | 1 + tools/anvil-daemon | 20 +++++++++++++- 6 files changed, 88 insertions(+), 6 deletions(-) diff --git a/Anvil/Tools/System.pm b/Anvil/Tools/System.pm index a6acd89f..08f02524 100644 --- a/Anvil/Tools/System.pm +++ b/Anvil/Tools/System.pm @@ -2587,6 +2587,10 @@ Parameters; This is the name of the daemon to disable. The exact name given is passed to C<< systemctl >>, so please be mindful of appropriate suffixes. +=head3 now (optional, default '0') + +If set to C<< 1 >>, the daemon will be stopped as well as disabled + =cut sub disable_daemon { @@ -2597,9 +2601,19 @@ sub disable_daemon $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->disable_daemon()" }}); my $daemon = defined $parameter->{daemon} ? $parameter->{daemon} : ""; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { daemon => $daemon }}); + my $now = defined $parameter->{now} ? $parameter->{now} : 0; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + daemon => $daemon, + now => $now, + }}); - my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{systemctl}." disable ".$daemon}); + my $shell_call = $anvil->data->{path}{exe}{systemctl}." disable ".$daemon; + if ($now) + { + $shell_call = $anvil->data->{path}{exe}{systemctl}." disable --now ".$daemon; + } + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }}); + my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code, @@ -3033,6 +3047,10 @@ Parameters; This is the name of the daemon to enable. The exact name given is passed to C<< systemctl >>, so please be mindful of appropriate suffixes. +=head3 now (optional, default '0' + +If set to c<< 1 >>, the daemon will be started now. + =cut sub enable_daemon { @@ -3043,9 +3061,19 @@ sub enable_daemon $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => $debug, key => "log_0125", variables => { method => "System->enable_daemon()" }}); my $daemon = defined $parameter->{daemon} ? $parameter->{daemon} : ""; - $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { daemon => $daemon }}); + my $now = defined $parameter->{now} ? $parameter->{now} : 0; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + daemon => $daemon, + now => $now, + }}); - my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $anvil->data->{path}{exe}{systemctl}." enable ".$daemon." 2>&1"}); + my $shell_call = $anvil->data->{path}{exe}{systemctl}." enable ".$daemon." 2>&1"; + if ($now) + { + $shell_call = $anvil->data->{path}{exe}{systemctl}." enable --now ".$daemon." 2>&1"; + } + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }}); + my ($output, $return_code) = $anvil->System->call({debug => $debug, shell_call => $shell_call}); $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { output => $output, return_code => $return_code, diff --git a/notes b/notes index 544bf03e..aee41508 100644 --- a/notes +++ b/notes @@ -14,6 +14,7 @@ web -s enable snmp -S enable -c1 private -a1 writeplus snmp -S enable -c2 public -a2 writeplus + Anvil! to Anvil! live migration; 1. Create LVs 2. Make sure /etc/hosts is populated diff --git a/scancore-agents/scan-drbd/scan-drbd b/scancore-agents/scan-drbd/scan-drbd index 5e8b9e5a..060060f5 100755 --- a/scancore-agents/scan-drbd/scan-drbd +++ b/scancore-agents/scan-drbd/scan-drbd @@ -1325,17 +1325,50 @@ WHERE my $scan_drbd_peer_uuid = $row->[0]; my $scan_drbd_peer_scan_drbd_volume_uuid = $row->[1]; my $scan_drbd_peer_host_name = $row->[2]; + my $scan_drbd_peer_connection_state = $row->[3]; $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { scan_drbd_peer_uuid => $scan_drbd_peer_uuid, scan_drbd_peer_scan_drbd_volume_uuid => $scan_drbd_peer_scan_drbd_volume_uuid, scan_drbd_peer_host_name => $scan_drbd_peer_host_name, + scan_drbd_peer_connection_state => $scan_drbd_peer_connection_state, }}); + # It's possible that a DELETED resource no longer has corresponding LVM data. If so, we'll + # purge this record. + if (($scan_drbd_peer_connection_state eq "DELETED") && (not exists $anvil->data->{volume_to_uuid}{$scan_drbd_peer_scan_drbd_volume_uuid})) + { + # Purge it. + my $resource_uuid = $anvil->data->{old}{scan_drbd_volume}{scan_drbd_volume_uuid}{$scan_drbd_peer_scan_drbd_volume_uuid}{scan_drbd_volume_scan_drbd_resource_uuid}; + my $volume_number = $anvil->data->{old}{scan_drbd_volume}{scan_drbd_volume_uuid}{$scan_drbd_peer_scan_drbd_volume_uuid}{scan_drbd_volume_number}; + my $resource_name = $anvil->data->{old}{scan_drbd_resource}{scan_drbd_resource_uuid}{$resource_uuid}{scan_drbd_resource_name}; + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + resource_uuid => $resource_uuid, + volume_number => $volume_number, + resource_name => $resource_name, + }}); + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, key => "scan_drbd_message_0035", variables => { + peer_name => $scan_drbd_peer_host_name, + resource_name => $resource_name, + volume_number => $volume_number, + }}); + + my $queries = []; + push @{$queries}, "DELETE FROM history.scan_drbd_peers WHERE scan_drbd_peer_uuid = '".$scan_drbd_peer_uuid."';"; + push @{$queries}, "DELETE FROM scan_drbd_peers WHERE scan_drbd_peer_uuid = '".$scan_drbd_peer_uuid."';"; + foreach my $query (@{$queries}) + { + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { query => $query }}); + } + $anvil->Database->write({query => $queries, source => $THIS_FILE, line => __LINE__}); + + next; + } + # Store the old data now. $anvil->data->{old}{scan_drbd_peer}{scan_drbd_peer_uuid}{$scan_drbd_peer_uuid}{processed} = 0; $anvil->data->{old}{scan_drbd_peer}{scan_drbd_peer_uuid}{$scan_drbd_peer_uuid}{scan_drbd_peer_scan_drbd_volume_uuid} = $scan_drbd_peer_scan_drbd_volume_uuid; $anvil->data->{old}{scan_drbd_peer}{scan_drbd_peer_uuid}{$scan_drbd_peer_uuid}{scan_drbd_peer_host_name} = $scan_drbd_peer_host_name; - $anvil->data->{old}{scan_drbd_peer}{scan_drbd_peer_uuid}{$scan_drbd_peer_uuid}{scan_drbd_peer_connection_state} = $row->[3]; + $anvil->data->{old}{scan_drbd_peer}{scan_drbd_peer_uuid}{$scan_drbd_peer_uuid}{scan_drbd_peer_connection_state} = $scan_drbd_peer_connection_state; $anvil->data->{old}{scan_drbd_peer}{scan_drbd_peer_uuid}{$scan_drbd_peer_uuid}{scan_drbd_peer_local_disk_state} = $row->[4]; $anvil->data->{old}{scan_drbd_peer}{scan_drbd_peer_uuid}{$scan_drbd_peer_uuid}{scan_drbd_peer_disk_state} = $row->[5]; $anvil->data->{old}{scan_drbd_peer}{scan_drbd_peer_uuid}{$scan_drbd_peer_uuid}{scan_drbd_peer_local_role} = $row->[6]; diff --git a/scancore-agents/scan-drbd/scan-drbd.xml b/scancore-agents/scan-drbd/scan-drbd.xml index a2c5e532..eb1a3c79 100644 --- a/scancore-agents/scan-drbd/scan-drbd.xml +++ b/scancore-agents/scan-drbd/scan-drbd.xml @@ -150,6 +150,7 @@ The global common configuration file: [#!variable!file!#] needs to be updated. T #!variable!diff!# ==== + The DRBD peer: [#!variable!peer_name!#] resource: [#!variable!resource_name!#] volume: [#!variable!volume_number!#] was deleted, and the corresponding LVM data no longer exists. Purging this resource's data. Enabled diff --git a/share/words.xml b/share/words.xml index 1ce8432e..6dd9c427 100644 --- a/share/words.xml +++ b/share/words.xml @@ -3224,6 +3224,7 @@ We will sleep a bit and try again. [ Warning ] - The command: [#!variable!command!#] is still using our database. [ Warning ] - While evaluating database shutdown, the host UUID: [#!variable!host_uuid!#] was not yet found in the database on host: [#!variable!db_uuid!#]. DB shutdown will not happen until all hosts are in all DBs. [ Warning ] - While preparing to record the state: [#!variable!state_info!#], the host UUID: [#!variable!host_uuid!#] was not yet found in the database on host: [#!variable!db_uuid!#]. NOT recording the state! + [ Warning ] - The daemon: [#!variable!daemon!#] was found running. It shouldn't be, and will now be stopped and disabled. diff --git a/tools/anvil-daemon b/tools/anvil-daemon index 6843c399..0caae802 100755 --- a/tools/anvil-daemon +++ b/tools/anvil-daemon @@ -251,7 +251,7 @@ while(1) check_ram($anvil); # Disconnect from the database(s) and sleep now. - $anvil->Database->disconnect({debug => 2}); + $anvil->Database->disconnect(); sleep(2); } @@ -698,6 +698,24 @@ sub handle_periodic_tasks # Now check to see if it's time to run daily tasks. if ($now_time >= $anvil->data->{timing}{next_daily_check}) { + # Make sure ksm and ksmtuned are disabled. + foreach my $daemon ("ksm.service", "ksmtuned.service") + { + my $status = $anvil->System->check_daemon({daemon => $daemon}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { + daemon => $daemon, + status => $status, + }}); + if ($status eq "1") + { + $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, 'print' => 1, level => 1, priority => "alert", key => "warning_0145", variables => { daemon => $daemon }}); + $anvil->System->disable_daemon({ + now => 1, + daemon => $daemon, + }); + } + } + ### NOTE: We call it once/day, but this will also trigger on restart of anvil-daemon. As such, we ### don't use '--force' and let striker-manage-install-target skip the repo update if it happened ### recently enough.