@@ -419,7 +419,7 @@ sub check_status
419
419
$env -> log (3, ' checking status of ' . $svc -> host_id);
420
420
if ($svc -> status_command) {
421
421
$env -> job( sub {
422
- return $env -> remote_exec($svc -> host, $svc -> status_command);
422
+ return $env -> remote_exec($svc -> host, $svc -> status_command, $svc );
423
423
}, sub {
424
424
my $exit_code = shift ;
425
425
if ($env -> dry_run) {
@@ -547,7 +547,7 @@ sub go
547
547
$svc -> last_status($go -> {trn_status });
548
548
push (@{$svc -> {wait_callbacks_ }}, $callback );
549
549
$env -> job( sub {
550
- return $env -> remote_exec($svc -> host, $svc -> {$cmd ." _command_" });
550
+ return $env -> remote_exec($svc -> host, $svc -> {$cmd ." _command_" }, $svc );
551
551
}, sub {
552
552
my $exit_code = shift ;
553
553
if ($exit_code != 0) {
@@ -845,6 +845,7 @@ sub new
845
845
probe_delay => 3,
846
846
colors => ($term =~ m / ^(xterm|screen|cygwin|rxvt)/ ? 1 : 0),
847
847
no_remote => [" " ],
848
+ sudo => 0,
848
849
help => 0,
849
850
};
850
851
@@ -866,6 +867,7 @@ sub new
866
867
' probe-delay=i' => \$opt -> {probe_delay },
867
868
' jobs|j=i' => \$opt -> {jobs },
868
869
' colors!' => \$opt -> {colors },
870
+ ' sudo|U' => \$opt -> {sudo },
869
871
' help|h' => \$opt -> {help },
870
872
);
871
873
@{$opt -> {no_remote }} = split (/ |,/ , join (' ,' , @{$opt -> {no_remote }}));
@@ -940,7 +942,7 @@ sub new
940
942
exit $env -> result;
941
943
}
942
944
943
- if ($priveleged_command && defined ($svcs -> effective_user) && !$env -> dry_run) {
945
+ if ($priveleged_command && defined ($svcs -> effective_user) && !$env -> dry_run && $opt -> { sudo } ) {
944
946
my $effective_user = $svcs -> effective_user;
945
947
my @eui = getpwnam ($effective_user );
946
948
if (@eui == 0) {
@@ -1242,6 +1244,7 @@ sub remote_exec
1242
1244
my $env = shift ;
1243
1245
my $host = shift ;
1244
1246
my $command = shift ;
1247
+ my $svc = shift ;
1245
1248
1246
1249
if ($env -> no_remote($host )) {
1247
1250
my $res = $env -> exec ($command );
@@ -1251,7 +1254,12 @@ sub remote_exec
1251
1254
1252
1255
return $status ;
1253
1256
}
1254
- my @args = (' /usr/bin/ssh' , @{$env -> {ssh_opt_ }}, $host , $command );
1257
+ my @ssh_opt = (@{$env -> {ssh_opt_ }});
1258
+
1259
+ if (defined ($svc ) && defined ($svc -> user)) {
1260
+ push (@ssh_opt , ' -l' , $svc -> user);
1261
+ }
1262
+ my @args = (' /usr/bin/ssh' , @ssh_opt , $host , $command );
1255
1263
my $res = $env -> exec (@args );
1256
1264
my $status = $res >> 8;
1257
1265
@@ -1636,6 +1644,10 @@ Sets probe count to N before probe procedure considered to be failed. Defaults t
1636
1644
1637
1645
Sets delay to N seconds between probe attempts. Default 3 sec.
1638
1646
1647
+ =item B<-U --sudo >
1648
+
1649
+ Use sudo to effective user before executing ssh commands.
1650
+
1639
1651
=item B<-n, --dry-run >
1640
1652
1641
1653
Do not execute commands
0 commit comments