Commit ce64063b authored by Matthieu Muffato's avatar Matthieu Muffato
Browse files

Meadow now has an interface to run an arbitrary command on a host, and...

Meadow now has an interface to run an arbitrary command on a host, and Queen+Valley use it to clean the temp directories of dead workers
parent 711ee00f
......@@ -323,4 +323,17 @@ sub submit_workers {
die "Please use a derived method";
}
=head2 run_on_host
Title : run_on_host
Function: Runs an arbitrary commands on the given host. The host is expected to belong to the meadow and be reachable
=cut
sub run_on_host {
my ($self, $meadow_host, $meadow_user, $command) = @_;
return system('ssh', '-o', 'BatchMode=yes', sprintf('%s@%s', $meadow_user, $meadow_host), @$command);
}
1;
......@@ -164,4 +164,11 @@ sub submit_workers_return_meadow_pids {
return \@children_pids;
}
sub run_on_host { # Overrides Meadow::run_on_host
my ($self, $meadow_host, $meadow_user, $command) = @_;
# We can assume the current host is $meadow_host and bypass ssh
return system(@$command);
}
1;
......@@ -442,6 +442,7 @@ sub check_for_dead_workers { # scans the whole Valley for lost Workers (but i
$worker->when_died( $report_entries->{$process_id}{'when_died'} );
$worker->cause_of_death( $report_entries->{$process_id}{'cause_of_death'} );
$self->register_worker_death( $worker );
$valley->cleanup_left_temp_directory( $worker );
}
if( %$report_entries ) { # use the opportunity to also store resource usage of the buried workers:
......
......@@ -247,5 +247,17 @@ sub status_of_all_our_workers_by_meadow_signature {
return \%worker_statuses;
}
sub cleanup_left_temp_directory {
my ($self, $worker) = @_;
# cleanup_left_temp_directory is called when garbage-collecting dead-workers,
# which is only possible for reachable meadows.
# This guarantees that $meadow is defined.
my $meadow = $self->available_meadow_hash->{$worker->meadow_type};
my $rc = $meadow->run_on_host($worker->meadow_host, $worker->meadow_user, ['rm', '-rf', $worker->temp_directory_name]);
$worker->worker_say(sprintf("Error: could not clean %s's temp directory '%s': %s\n", $worker->meadow_host, $worker->temp_directory_name, $@)) if $rc;
}
1;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment