]> mj.ucw.cz Git - bex.git/commitdiff
Make destination user configurable per machine
authorMartin Mares <mj@ucw.cz>
Fri, 29 Mar 2019 20:16:31 +0000 (21:16 +0100)
committerMartin Mares <mj@ucw.cz>
Fri, 29 Mar 2019 20:18:10 +0000 (21:18 +0100)
cf/config
lib/bin/bex-run
lib/perl/BEX/Config.pm

index 09c1b1ba4c13aeebdce867ce6db603429b94be20..ea7bbc32b5324d7288c96abf14c0a588b400b693 100644 (file)
--- 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'],
 );
index c0378fb28df332d0fab86980278999bcc4ac353b..25241201094e2cbea1256b72fa1950e32ed75446 100755 (executable)
@@ -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);
index 4ac7bbb587dd00f22a341541cfc54aa7218dbdfa..f6239f0fb289e7898152af23bbb593ee71e42f8a 100644 (file)
@@ -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';