X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=brun;h=760bf9ca172f1f7e8f0bcaf92df7c64109bb0386;hb=f0db6a85bb186258d023ff64f10cc7a7440256f1;hp=01bff140e7368ea823743936c7e0d80fadb37b20;hpb=8d34ddafee25097b3dec59e569200ff2dfa1f4ac;p=bex.git diff --git a/brun b/brun index 01bff14..760bf9c 100755 --- a/brun +++ b/brun @@ -22,7 +22,7 @@ Usage: brun [] [[!] ...] Options: -j, --job= Run only the specified job --q, --queue= Run jobs in the given queue +-q, --queue= Select job queue --status-fifo= Send status updates to the given named pipe AMEN @@ -32,16 +32,19 @@ if (defined $status_fifo) { autoflush $status_fd, 1; } -sub send_status($$$) { - my ($mach, $job, $status) = @_; +sub update_status($$$$;$) { + my ($mach, $job, $status, $log_on_queue, $msg) = @_; if ($status_fd) { print $status_fd "! $mach $job $status\n"; } + if ($log_on_queue) { + $log_on_queue->log($mach, $job, $status, $msg); + } } sub ping_machine($) { my ($mach) = @_; - send_status($mach, '-', 'PING'); + update_status($mach, '-', 'PING', undef); `ping -c1 -n $mach >/dev/null 2>/dev/null`; return !$?; } @@ -56,7 +59,7 @@ sub run_job($$$) { my $tmp = $queue->temp_file($mach, $jid); open T, '>', $tmp or die; if (defined $BEX::Config::job_prolog) { - open P, $BEX::Config::job_prolog or return "Cannot open prolog: $!"; + open P, $BEX::Config::job_prolog or return ('INTERR', "Cannot open prolog: $!"); while (

) { print T; } close P; } else { @@ -65,24 +68,24 @@ sub run_job($$$) { print T "# BEX job ", $jid, "\n"; print T $job->{'body'}; if (defined $BEX::Config::job_epilog) { - open E, $BEX::Config::job_epilog or return "Cannot open epilog: $!"; + open E, $BEX::Config::job_epilog or return ('INTERR', "Cannot open epilog: $!"); while () { print T; } close E; } close T; - send_status($mach, $jid, 'SEND'); + 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'`; - !$? && defined($rtmp) && $rtmp ne '' or return "Transfer failed"; + !$? && defined($rtmp) && $rtmp ne '' or return ('NOXFER', 'Transfer failed'); chomp $rtmp; - send_status($mach, $jid, 'RUN'); + update_status($mach, $jid, 'RUN', $queue); system 'ssh', '-t', $mach, "$rtmp ; e=\$? ; rm -f $rtmp ; exit \$e"; if ($?) { - return 'Failed'; + return ('FAILED', 'Job failed'); } else { - return 'OK'; + return ('OK', undef); } } @@ -91,7 +94,7 @@ my $queue = BEX::Queue->new($queue_name); for my $mach (@machines) { my @q = $queue->scan($mach) or next; - send_status($mach, '-', 'INIT'); + update_status($mach, '-', 'INIT', undef); my $ping; for my $jid (@q) { if (defined $given_job) { @@ -103,24 +106,23 @@ for my $mach (@machines) { }; print "### Running $jid (", $job->attr('Subject'), ") on $mach ###\n"; $ping //= ping_machine($mach); - my $s; + my $s, $msg; if (!$ping) { - $s = 'No ping'; + ($s, $msg) = ('NOPING', 'Does not ping'); } else { - $s = run_job($job, $queue, $mach); + ($s, $msg) = run_job($job, $queue, $mach); } + update_status($mach, $jid, $s, $queue, $msg); - BEX::log("$mach $jid $s"); if ($s eq 'OK') { print "+++ OK\n"; $queue->remove($mach, $jid); - send_status($mach, $jid, 'OK'); } else { - print "--- $s\n"; + print "--- $s: $msg\n"; $stat->{'Status'} = $s; + $stat->{'Message'} = $msg; $queue->write_job_status($mach, $jid, $stat); - send_status($mach, $jid, 'ERR'); } } - send_status($mach, '-', 'DONE'); + update_status($mach, '-', 'DONE', undef); }