From f5c3d7a2d47c6c582b7bfdcb5a2e1bcdf4168f8d Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 31 Oct 2011 11:41:18 +0100 Subject: [PATCH] Host names are configurable --- BEX.cf | 2 +- TODO | 2 +- brun | 8 +++++--- lib/BEX/Config.pm | 9 ++++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/BEX.cf b/BEX.cf index f749911..09c1b1b 100644 --- a/BEX.cf +++ b/BEX.cf @@ -4,7 +4,7 @@ package BEX::Config; %machines = ( - 'albireo' => {}, + 'albireo' => { 'Host' => 'albireo.burrow.ucw.cz' }, 'localhost' => {}, 'home' => ['albireo', 'localhost'], ); diff --git a/TODO b/TODO index 6b146e7..b1b2a01 100644 --- a/TODO +++ b/TODO @@ -10,4 +10,4 @@ - ssh options - Detector of orphans (unused queue dirs, jobs on non-existent machines, non-queued jobs) - job failed => give a more explanatory message -- configurable hostnames of hosts +- configurable ping diff --git a/brun b/brun index 767eefb..b22d5b6 100755 --- a/brun +++ b/brun @@ -45,13 +45,15 @@ sub update_status($$$$;$) { sub ping_machine($) { my ($mach) = @_; update_status($mach, '-', 'PING', undef); - `ping -c1 -n $mach >/dev/null 2>/dev/null`; + my $host = BEX::Config::host_name($mach); + `ping -c1 -n $host >/dev/null 2>/dev/null`; return !$?; } sub run_job($$$) { my ($job, $queue, $mach) = @_; my $jid = $job->{'ID'}; + my $host = BEX::Config::host_name($mach); my $tmp = $queue->temp_file($mach, $jid); open T, '>', $tmp or die; @@ -73,13 +75,13 @@ sub run_job($$$) { update_status($mach, $jid, 'SEND', undef); my $cmd = 't=$(mktemp -t bex-XXXXXXXX) && cat >$t && chmod u+x $t && echo $t'; - my $rtmp = `ssh <$tmp $mach '$cmd'`; + my $rtmp = `ssh <$tmp $host '$cmd'`; !$? && defined($rtmp) && $rtmp ne '' or return ('NOXFER', 'Transfer failed'); chomp $rtmp; update_status($mach, $jid, 'RUN', $queue); my $lf = $queue->log_file($mach, $jid); - system 'bash', '-o', 'pipefail', '-c', "ssh -t $mach '$rtmp ; e=\$? ; rm -f $rtmp ; exit \$e' 2>&1 | tee -a $lf"; + system 'bash', '-o', 'pipefail', '-c', "ssh -t $host '$rtmp ; e=\$? ; rm -f $rtmp ; exit \$e' 2>&1 | tee -a $lf"; if ($?) { return ('FAILED', 'Job failed'); } else { diff --git a/lib/BEX/Config.pm b/lib/BEX/Config.pm index a364b2c..90c5700 100644 --- a/lib/BEX/Config.pm +++ b/lib/BEX/Config.pm @@ -9,11 +9,13 @@ package BEX::Config; # This file specifies default values, which can be overridden in BEX.cf # A hash of all known machines and groups -# 'name' => { } for a machine +# 'name' => { Option => ... } for a machine; options: +# Host => 'name' Host name to use in ssh, ping, ... # 'name' => ['a','b','c'] for a group containing specified machines/subgroups our %machines = ( ); + # A file whose contents should be prepended before the job. Should start with the "#!" line. our $job_prolog = 'prolog'; @@ -54,6 +56,11 @@ sub parse_machine_list(@) { return sort grep { $set{$_} } keys %set; } +sub host_name($) { + my ($mach) = @_; + return $machines{$mach}->{'Host'} // $mach; +} + require 'BEX.cf'; 42; -- 2.39.2