RunCommand: Capture the output of the commands

This commit is contained in:
Janne Heß 2021-12-26 16:14:10 +01:00 committed by Cole Helbling
parent 001539c3d2
commit 4cb5e6cd94
2 changed files with 20 additions and 2 deletions

View file

@ -275,7 +275,11 @@ in
mkdir -m 0700 -p ${baseDir}/queue-runner
mkdir -m 0750 -p ${baseDir}/build-logs
chown hydra-queue-runner.hydra ${baseDir}/queue-runner ${baseDir}/build-logs
mkdir -m 0750 -p ${baseDir}/runcommand-logs
chown hydra-queue-runner.hydra \
${baseDir}/queue-runner \
${baseDir}/build-logs \
${baseDir}/runcommand-logs
${optionalString haveLocalDB ''
if ! [ -e ${baseDir}/.db-created ]; then
@ -457,6 +461,7 @@ in
script =
''
find /var/lib/hydra/build-logs -type f -name "*.drv" -mtime +3 -size +0c | xargs -r bzip2 -v -f
find /var/lib/hydra/runcommand-logs -type f -name "*.drv" -mtime +3 -size +0c | xargs -r bzip2 -v -f
'';
startAt = "Sun 01:45";
};

View file

@ -5,6 +5,8 @@ use warnings;
use parent 'Hydra::Plugin';
use experimental 'smartmatch';
use JSON::MaybeXS;
use Digest::SHA1 qw(sha1_hex);
use Hydra::Model::DB;
sub isEnabled {
my ($self) = @_;
@ -160,7 +162,18 @@ sub buildFinished {
$runlog->started();
system("$command") == 0
# Prepare log collection
my $filename = sha1_hex($command) . "-" . $build->get_column('id');
my $dir = Hydra::Model::DB::getHydraPath . "/runcommand-logs/" . substr($filename, 0, 2);
my $logpath = "$dir/$filename";
mkdir($dir, oct(755));
# This creates the file with the correct permissions
open(my $f, '>', $logpath);
close($f);
chmod(oct(644), $logpath);
# Run the command
system("$command 1>$logpath 2>&1") == 0
or warn "notification command '$command' failed with exit status $? ($!)\n";
$runlog->completed_with_child_error($?, $!);