From 59ade94124d1615b9f0618f1d2b5c59001404ae4 Mon Sep 17 00:00:00 2001 From: digimer Date: Mon, 7 Aug 2023 22:10:43 -0400 Subject: [PATCH] * Added PID logging as an option, and enabled it in ocf:alteeve:server * Updated DRBD->manage_resource() to take the task 'adjust'. * Updated ocf:alteeve:server's start_drbd_resource() to call adjust if startup of a resource isn't needd. Signed-off-by: digimer --- Anvil/Tools.pm | 1 + Anvil/Tools/DRBD.pm | 43 +++++++++++++++++++++++++++++++++++++++++-- Anvil/Tools/Log.pm | 4 ++++ ocf/alteeve/server | 12 +++++++++++- 4 files changed, 57 insertions(+), 3 deletions(-) diff --git a/Anvil/Tools.pm b/Anvil/Tools.pm index 6df7b561..4dbd25fb 100644 --- a/Anvil/Tools.pm +++ b/Anvil/Tools.pm @@ -981,6 +981,7 @@ sub _set_defaults facility => "local0", language => "en_CA", level => 1, + pids => 0, secure => 0, server => "", tag => "anvil", diff --git a/Anvil/Tools/DRBD.pm b/Anvil/Tools/DRBD.pm index 858e0c19..fbda99eb 100644 --- a/Anvil/Tools/DRBD.pm +++ b/Anvil/Tools/DRBD.pm @@ -2451,7 +2451,7 @@ sub get_status =head2 manage_resource -This takes a task, C<< up >>, C<< down >>, C<< primary >>, or C<< secondary >> and a resource name and acts on the request. +This takes a task, C<< up >>, C<< down >>, C<< primary >>, C<< secondary >>, or C<< adjust >> and a resource name and acts on the request. This returns the return code from the C<< drbdadm >> call. If C<< 255 >> is returned, then we did not get the actual return code from C<< drbdadm >>. @@ -2475,7 +2475,7 @@ This is the name of the resource being acted upon. =head3 task (required) -This is the action to take. Valid tasks are: C<< up >>, C<< down >>, C<< primary >>, and C<< secondary >>. +This is the action to take. Valid tasks are: C<< up >>, C<< down >>, C<< primary >>, C<< secondary >>, and C<< adjust >>. If C<< target >> is set, this will be the user we connect to the remote machine as. @@ -2518,6 +2518,45 @@ sub manage_resource return(1); } + # If the task is 'adjust', do just that. + if ($task eq "adjust") + { + # Reset to the values in the config and return. + my $shell_call = $anvil->data->{path}{exe}{drbdadm}." adjust ".$resource; + my $output = ""; + my $return_code = 255; + if ($anvil->Network->is_local({host => $target})) + { + # Local. + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }}); + ($output, $return_code) = $anvil->System->call({shell_call => $shell_call}); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + output => $output, + return_code => $return_code, + }}); + } + else + { + # Remote call. + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { shell_call => $shell_call }}); + ($output, my $error, $return_code) = $anvil->Remote->call({ + debug => $debug, + shell_call => $shell_call, + target => $target, + port => $port, + password => $password, + remote_user => $remote_user, + }); + $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => $debug, list => { + error => $error, + output => $output, + return_code => $return_code, + }}); + } + + return($return_code); + } + ### TODO: When taking down a resource, check to see if any machine is SyncTarget and take it/them ### down first. See anvil-rename-server -> verify_server_is_off() for the logic. ### TODO: Sanity check the resource name and task requested. diff --git a/Anvil/Tools/Log.pm b/Anvil/Tools/Log.pm index fecc9c59..db627adb 100644 --- a/Anvil/Tools/Log.pm +++ b/Anvil/Tools/Log.pm @@ -373,6 +373,10 @@ sub entry $job_uuid =~ s/^(\w+?)-.*$/$1/; $string .= "[".$job_uuid."]:"; } + if ($anvil->data->{defaults}{'log'}{pids}) + { + $string .= "[".$$."]:"; + } if (exists $anvil->data->{'log'}{scan_agent}) { $string .= "[".$anvil->data->{'log'}{scan_agent}."]:"; diff --git a/ocf/alteeve/server b/ocf/alteeve/server index 9d19f6b0..6e01c240 100755 --- a/ocf/alteeve/server +++ b/ocf/alteeve/server @@ -100,7 +100,8 @@ $| = 1; # NOTE: Setting 'log_level' and 'log_secure' here will get overridden in the main lopp. Use the Log methods # in the loop as well to override defaults in code. my $anvil = Anvil::Tools->new(); -#$anvil->Log->level({set => 2}); +# Log PIDs +$anvil->data->{defaults}{'log'}{pids} = 1; ### Read or Set the environment variables # This is the name of the server we're managing. # Example values: @@ -829,6 +830,15 @@ sub start_drbd_resource } } } + else + { + # Call an adjust to reset the config, in case something like 'allow-two-primaries' was + # enabled on one node but not the other. + $anvil->DRBD->manage_resource({ + resource => $resource, + task => "adjust", + }); + } ### NOTE: We always check the peer now, in case it's resource is down and ours happens to be up. # See if we're inconsistent and, if so, if we can connect our peers.