From df67ec8ada87a0bbd5c1dc16885629c8beb5a98c Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 29 Mar 2019 21:16:31 +0100 Subject: [PATCH] Make destination user configurable per machine --- cf/config | 2 +- lib/bin/bex-run | 8 ++++---- lib/perl/BEX/Config.pm | 16 +++++++++++++--- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cf/config b/cf/config index 09c1b1b..ea7bbc3 100644 --- a/cf/config +++ b/cf/config @@ -4,7 +4,7 @@ package BEX::Config; %machines = ( - 'albireo' => { 'Host' => 'albireo.burrow.ucw.cz' }, + 'albireo' => { 'Host' => 'albireo.burrow.ucw.cz', 'User' => 'root' }, 'localhost' => {}, 'home' => ['albireo', 'localhost'], ); diff --git a/lib/bin/bex-run b/lib/bin/bex-run index c0378fb..2524120 100755 --- a/lib/bin/bex-run +++ b/lib/bin/bex-run @@ -56,7 +56,7 @@ sub ping_machine($) { if (!defined $pings{$mach}) { if ($BEX::Config::ping_hosts) { update_status($mach, '-', 'PING', undef); - my $host = BEX::Config::host_name($mach); + my $host = BEX::Config::host_name($mach, 0); `ping -c1 -n $host >/dev/null 2>/dev/null`; $pings{$mach} = !$?; } else { @@ -87,7 +87,7 @@ sub run_job_prep($$$) { my $jid = $job->id; update_status($mach, $jid, 'PREP', $queue); my $lf = $queue->log_file($mach, $jid); - $ENV{'HOST'} = BEX::Config::host_name($mach); + $ENV{'HOST'} = BEX::Config::host_name($mach, 0); system 'bash', '-o', 'pipefail', '-c', "( $prep ) 2>&1 | tee -a $lf"; delete $ENV{'HOST'}; if ($?) { @@ -123,7 +123,7 @@ sub make_job_body($$$) { sub run_simple_job($$$$) { my ($job, $queue, $mach, $body) = @_; - my $host = BEX::Config::host_name($mach); + my $host = BEX::Config::host_name($mach, 1); my $jid = $job->id; update_status($mach, $jid, 'SEND', undef); @@ -146,7 +146,7 @@ sub run_simple_job($$$$) { sub run_complex_job($$$$) { my ($job, $queue, $mach, $body) = @_; - my $host = BEX::Config::host_name($mach); + my $host = BEX::Config::host_name($mach, 1); my $jid = $job->id; update_status($mach, $jid, 'SEND', undef); diff --git a/lib/perl/BEX/Config.pm b/lib/perl/BEX/Config.pm index 4ac7bbb..f6239f0 100644 --- a/lib/perl/BEX/Config.pm +++ b/lib/perl/BEX/Config.pm @@ -56,6 +56,9 @@ our $skip_on_fail = 0; # How we run ssh (including options) our $ssh_command = "ssh"; +# Which user we log in as (if any) +our $ssh_user; + # How we run rsync to upload attachments (including options) our $rsync_command = "rsync -a"; @@ -93,9 +96,16 @@ sub parse_machine_list(@) { return sort grep { $set{$_} } keys %set; } -sub host_name($) { - my ($mach) = @_; - return $machines{$mach}->{'Host'} // $mach; +sub host_name($$) { + my ($mach, $want_user) = @_; + my $host = $machines{$mach}->{'Host'} // $mach; + if ($want_user) { + my $user = $machines{$mach}->{'User'} // $ssh_user; + if (defined $user) { + return $user . '@' . $host; + } + } + return $host; } require $cf_dir . '/config'; -- 2.39.5