You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vcl.apache.org by ar...@apache.org on 2016/01/14 22:21:35 UTC
svn commit: r1724690 - in /vcl/trunk/managementnode/lib/VCL:
Module/OS/Linux/ManagementNode.pm Module/Semaphore.pm utils.pm
Author: arkurth
Date: Thu Jan 14 21:21:35 2016
New Revision: 1724690
URL: http://svn.apache.org/viewvc?rev=1724690&view=rev
Log:
VCL-924
Added $timeout_seconds argument to utils.pm::run_command. It uses an alarm if this argument is provided. Updated ManagementNode.pm::execute which calls utils.pm::run_command to pass the argument if provided. Added argument to lsof command in Semaphore.pm.
Modified:
vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ManagementNode.pm
vcl/trunk/managementnode/lib/VCL/Module/Semaphore.pm
vcl/trunk/managementnode/lib/VCL/utils.pm
Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ManagementNode.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ManagementNode.pm?rev=1724690&r1=1724689&r2=1724690&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ManagementNode.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Linux/ManagementNode.pm Thu Jan 14 21:21:35 2016
@@ -104,7 +104,7 @@ sub initialize {
=head2 execute
- Parameters : $command, $display_output (optional)
+ Parameters : $command, $display_output (optional), $timeout_seconds (optional)
Returns : array
Description :
@@ -127,8 +127,10 @@ sub execute {
# Get 2nd display output argument if supplied, or set default value
my $display_output = shift || '0';
+ my $timeout_seconds = shift;
+
# Run the command
- my ($exit_status, $output) = run_command($command, !$display_output);
+ my ($exit_status, $output) = run_command($command, !$display_output, $timeout_seconds);
if (defined($exit_status) && defined($output)) {
if ($display_output) {
notify($ERRORS{'OK'}, 0, "executed command: '$command', exit status: $exit_status, output:\n" . join("\n", @$output)) if $display_output;
Modified: vcl/trunk/managementnode/lib/VCL/Module/Semaphore.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/Semaphore.pm?rev=1724690&r1=1724689&r2=1724690&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/Semaphore.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/Semaphore.pm Thu Jan 14 21:21:35 2016
@@ -250,7 +250,7 @@ sub get_lockfile_owning_pid {
}
# Run lsof to determine which process is locking the file
- my ($exit_status, $output) = $self->mn_os->execute("/usr/sbin/lsof -Fp $file_path", 0);
+ my ($exit_status, $output) = $self->mn_os->execute("/usr/sbin/lsof -Fp $file_path", 0, 10);
if (!defined($output)) {
notify($ERRORS{'WARNING'}, 0, "failed to run losf command to determine which process is locking the file: $file_path");
return;
@@ -272,7 +272,7 @@ sub get_lockfile_owning_pid {
return;
}
else {
- notify($ERRORS{'DEBUG'}, 0, "file is not locked of lockfile: $file_path");
+ notify($ERRORS{'DEBUG'}, 0, "file is not locked: $file_path");
return ();
}
}
Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL: http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1724690&r1=1724689&r2=1724690&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Thu Jan 14 21:21:35 2016
@@ -9264,7 +9264,7 @@ EOF
=head2 run_command
- Parameters : string
+ Parameters : $command, $no_output (optional), $timeout_seconds (optional)
Returns : array if command run, undefined if it didn't
Description : Runs a command locally on the management node.
If command completed successfully, an array containing
@@ -9278,27 +9278,56 @@ EOF
=cut
sub run_command {
- my ($command, $no_output) = @_;
+ my ($command, $no_output, $timeout_seconds) = @_;
+ my @output;
my $output_string;
- $output_string = `$command 2>&1`;
- $output_string = '' unless $output_string;
+ my $exit_status;
+ my $timeout_flag = 0;
- my $exit_status = $?;
- if ($exit_status >= 0) {
- $exit_status = $exit_status >> 8;
+ eval {
+ # Override the die and alarm handlers
+ local $SIG{__DIE__} = sub{};
+
+ local $SIG{__WARN__} = sub {
+ my $warning_message = shift || '';
+ notify($ERRORS{'WARNING'}, 0, "warning was generated attempting to run command: $warning_message");
+ };
+
+ local $SIG{ALRM} = sub {
+ $timeout_flag = 1;
+ die;
+ };
+
+ if ($timeout_seconds) {
+ notify($ERRORS{'DEBUG'}, 0, "waiting up to $timeout_seconds seconds for command to finish: '$command'");
+ alarm $timeout_seconds;
+ }
+
+ $output_string = `$command 2>&1`;
+
+ # Save the exit status
+ $exit_status = $?;
+ if ($exit_status >= 0) {
+ $exit_status = $exit_status >> 8;
+ }
+
+ # Remove any trailing newlines from the output
+ chomp $output_string;
+
+ # Split the output string into an array of lines
+ @output = split(/[\r\n]+/, $output_string);
+ };
+
+ if ($timeout_flag) {
+ notify($ERRORS{'WARNING'}, 0, "command timed out after $timeout_seconds seconds: '$command'");
+ kill_child_processes($PID);
+ return;
}
-
-
- # Remove any trailing newlines from the output
- chomp $output_string;
-
- # Split the output string into an array of lines
- my @output = split(/[\r\n]+/, $output_string);
-
- if (!$no_output) {
- notify($ERRORS{'DEBUG'}, 0, "executed command: $command, exit status: $exit_status, output:\n" . join("\n", @output));
+ elsif (!$no_output) {
+ notify($ERRORS{'DEBUG'}, 0, "executed command: '$command', exit status: $exit_status, output:\n" . join("\n", @output));
}
+
return ($exit_status, \@output);
}