diff options
-rwxr-xr-x | iurt2 | 117 |
1 files changed, 67 insertions, 50 deletions
@@ -25,6 +25,7 @@ use strict; use Hdlist; use Data::Dumper; use URPM; +use File::NCopy qw(copy); use MIME::Words qw(encode_mimewords); use Fcntl ':flock'; my $home = '/home/mandrake/'; @@ -74,7 +75,7 @@ my (@stat) = stat $pidfile; if ($pid && getpgrp $pid != -1) { my $time = $stat[9]; if ($time < time - 36000) { - print "An other iurt pid $pid is running for a very long time, killing it\n"; + print "iurt: an other iurt pid $pid is running for a very long time, killing it\n"; my $i; while ($i < 5 && getpgrp $pid != -1) { kill_for_good($pid); @@ -82,11 +83,11 @@ my (@stat) = stat $pidfile; sleep 1 } } else { - print "An other iurt is running for $my_arch, pid $pid, since ",time - $time," seconds\n"; + print "iurt: an other iurt is running for $my_arch, pid $pid, since ",time - $time," seconds\n"; exit } } else { - print "A previous iurt for $my_arch seems dead, cleaning.\n"; + print "iurt: a previous iurt for $my_arch seems dead, cleaning.\n"; unlink $pidfile } }; @@ -96,22 +97,24 @@ print PID $$; close PID; my $cache = "$cache_home/iurt.$distro_tag.cache"; -print "Loading cache file $cache\n"; +print "iurt: loading cache file $cache\n"; eval { require $cache }; $::rpm_srpm ||= {}; $::failure ||= {}; $::queue ||= {}; $::warning ||= {}; +$::run ||= {}; my %big; my %srpm_version; my @wrong_rpm; foreach my $arch (@supported_arch) { my $rpms_dir = "/mnt/BIG/dis/$distro_version/$arch/media/$media/"; - print "Checking current packages in $rpms_dir\n"; + print "iurt: checking current packages in $rpms_dir\n"; opendir my $rpmdir, $rpms_dir; foreach my $rpm (readdir $rpmdir) { - my ($rarch, $srpm) = update_srpm($rpms_dir, $rpm) or next; + my ($rarch, $srpm) = update_srpm($rpms_dir, $rpm); + $rarch or next; $big{$rpm} = 1; $::queue->{$srpm}{$arch} = 1; $::queue->{$srpm}{$rarch} = 1; @@ -124,15 +127,16 @@ if ($check_queue) { my $dir = "$base_dir/build/RPMS/"; opendir my $rpmdir, $dir; - print "Checking upload queue in $dir\n"; + print "iurt: checking upload queue in $dir\n"; foreach my $rpm (readdir $rpmdir) { $rpm =~ /\.rpm$/ or next; if ($big{$rpm}) { - print "Cleaning $rpm\n"; + print "iurt: cleaning $rpm\n"; unlink "$dir/$rpm"; next } - my ($arch, $srpm) = update_srpm($dir, $rpm) or next; + my ($arch, $srpm) = update_srpm($dir, $rpm); + $arch or next; $::queue->{$srpm}{$arch} = 1; check_version($srpm) } @@ -152,7 +156,7 @@ my %done_rpm; # FIXME all the rep but the first one are cleaned # foreach my $dir ("/mnt/BIG/dis/$distro_version/SRPMS/$media/", @special_srpm_dir) { - print "Checking SRPMS dir $dir\n"; + print "iurt: checking SRPMS dir $dir\n"; opendir my $rpmdir, $dir; foreach my $srpm (readdir $rpmdir) { if ($srpm =~ /^\@\d+:(.*)/) { @@ -171,7 +175,7 @@ foreach my $dir ("/mnt/BIG/dis/$distro_version/SRPMS/$media/", @special_srpm_dir my $changelog = $hdr->queryformat("%{CHANGELOGNAME}"); my ($mail) = $changelog =~ /<(.*@.*)>/; $maint{$srpm} = $mail; - print "Will try to compile $srpm\n"; + print "iurt: will try to compile $srpm\n"; push @todo, [ $dir , $srpm ] } foreach my $arch (@supported_arch) { @@ -179,7 +183,7 @@ foreach my $dir ("/mnt/BIG/dis/$distro_version/SRPMS/$media/", @special_srpm_dir } } if ($clean && ($rep{$srpm} || $ok)) { - print "Cleaning $dir/$srpm\n"; + print "iurt: cleaning $dir/$srpm\n"; unlink "$dir/build/$srpm"; unlink "$dir/$srpm" } @@ -189,22 +193,26 @@ foreach my $dir ("/mnt/BIG/dis/$distro_version/SRPMS/$media/", @special_srpm_dir closedir $rpmdir } +$::run->{$distro_tag}{$my_arch}++; +my $run = $::run->{$distro_tag}{$my_arch}++; + dump_cache(); if (!@todo) { - print "Nothing to do\n"; + print "iurt: nothing to do\n"; exit } -print "Checking basesystem tar\n"; +print "iurt: checking basesystem tar\n"; my $chroot = "$local_home/chroot"; my $chroot_tar = "$chroot-$distro_tag.$my_arch.tar.gz"; -perform_command("sudo ~warly/files/cvs//mdk/soft/rpm-rebuilder/install-chroot-tar.sh cooker /mnt/BIG/distrib/$distro_version/$my_arch/media/main/ $chroot_tar $chroot 501 basesystem rpm-build", 'maintainers@mandriva.com', "[REBUILD] Creating the inital chroot for $distro_tag on $my_arch failed", 'chroot_inititialization',1); +perform_command("sudo ~warly/files/cvs//mdk/soft/rpm-rebuilder/install-chroot-tar.sh cooker /mnt/BIG/distrib/$distro_version/$my_arch/media/main/ $chroot_tar $chroot 501 basesystem rpm-build", mail => 'maintainers@mandriva.com', error => "[REBUILD] Creating the inital chroot for $distro_tag on $my_arch failed", hash => 'chroot_inititialization', die => 1); -my $local_spool = "$local_home/$distro_tag/$my_arch"; -if (!-d "$local_home/$distro_tag/") { - mkdir "$local_home/$distro_tag"; +my $local_spool = "$local_home/iurt/$distro_tag/$my_arch"; +if (!-d "$local_home/iurt/$distro_tag/") { + mkdir "$local_home/iurt/$distro_tag"; + mkdir "$local_home/iurt/$distro_tag"; if (!-d $local_spool) { mkdir $local_spool; mkdir "$local_spool/log" @@ -217,10 +225,10 @@ foreach my $t (@todo) { $done{$srpm} and next; $done{$srpm} = 1; check_version($srpm) or next; - print "Installing a new chroot for $srpm in $chroot\n"; - -d $chroot and perform_command("sudo rm -rf $chroot", 'warly@mandriva.com', "[REBUILD] Deleting of old chroot $chroot failed", 'chroot_deletion', 1); + print "iurt: installing a new chroot for $srpm in $chroot\n"; + -d $chroot and perform_command("sudo rm -rf $chroot", mail => 'warly@mandriva.com', error => "[REBUILD] Deleting of old chroot $chroot failed", hash => 'chroot_deletion', die => 1); mkdir $chroot; - perform_command("pushd $chroot && sudo tar xvf $chroot_tar", 'warly@mandriva.com', "[REBUILD] creating the initial chroot $chroot failed", 'chroot_init', 1); + perform_command("pushd $chroot && sudo tar xvf $chroot_tar", mail => 'warly@mandriva.com', error => "[REBUILD] creating the initial chroot $chroot failed", hash => 'chroot_init', die => 1); dump_rpmmacros("$chroot/home/builder/.rpmmacros"); @@ -236,30 +244,32 @@ foreach my $t (@todo) { print "Installing build dependencies of $srpm...\n"; # FIXME unfortunately urpmi stalls quite often system(qq{sudo pkill -9 -u root -f "urpmi --root $chroot"}); - perform_command("sudo urpmi -v --root $chroot --no-verify-rpm -s --auto $dir/$srpm", $maintainer, "[REBUILD] install of build dependencies of $srpm failed on $my_arch", "build_deps_$srpm", 0, 600, $cc, "$local_spool/log/") or next; - perform_command("sudo $chroot rpm -qa", '', "", "rpm_qa_$srpm", 60, '', 1) or next; + perform_command("sudo urpmi -v --root $chroot --no-verify-rpm -s --auto $dir/$srpm", mail => $maintainer, error => "[REBUILD] install of build dependencies of $srpm failed on $my_arch", hash => "install_deps_$srpm", timeout => 600, cc => $cc, log => "$local_spool/log/") or next; + perform_command("sudo chroot $chroot rpm -qa", hash => "rpm_qa_$srpm", timeout => 60, log => "$local_spool/log/") or next; print "Copying $srpm to $chroot\n"; - perform_command("sudo cp $dir/$srpm $chroot/home/builder/rpm/SRPMS/", 'warly@mandriva.com', "[REBUILD] cannot copy $srpm to $chroot", "copy_$srpm") or next; + perform_command("sudo cp $dir/$srpm $chroot/home/builder/rpm/SRPMS/", mail => 'warly@mandriva.com', error => "[REBUILD] cannot copy $srpm to $chroot", hash => "copy_$srpm") or next; print "Compiling $srpm\n"; #system(qq{sudo chroot $chroot /bin/su builder -c "mkdir rpm/RPMS/x86_64 rpm/RPMS/noarch"}); - if (!perform_command(qq{TMP=/home/builder/tmp/ sudo chroot $chroot /bin/su builder -c "rpm --rebuild /home/builder/rpm/SRPMS/$srpm"}, $maintainer, "[REBUILD] $srpm from $distro_tag does not build correctly on $my_arch", $srpm, 0, 18000, $cc, 1, 1)) { + if (!perform_command(qq{TMP=/home/builder/tmp/ sudo chroot $chroot /bin/su builder -c "rpm --rebuild /home/builder/rpm/SRPMS/$srpm"}, mail => $maintainer, error => "[REBUILD] $srpm from $distro_tag does not build correctly on $my_arch", hash => "build_$srpm", timeout => 18000, cc => $cc, log => "$local_spool/log/", freq => 1)) { $::failure->{$srpm}{$my_arch} = 1; next } - # FIXME try to install the packages afterwards - if (!perform_command("sudo urpmi --root $chroot --no-verify-rpm --auto $chroot/home/builder/rpm/RPMS/*/*.rpm", $maintainer, "[REBUILD] binaries packages generated from $srpm do not install correctly", "binary_test_$srpm", 0, 300, 0, 0, 1)) { + if (!perform_command("sudo urpmi --root $chroot --no-verify-rpm --auto $chroot/home/builder/rpm/RPMS/*/*.rpm", mail => $maintainer, error => "[REBUILD] binaries packages generated from $srpm do not install correctly", hash => "binary_test_$srpm", timeout => 300, freq => 1)) { $::failure->{$srpm}{$my_arch} = 1; + exit; next } system("cp $chroot/home/builder/rpm/RPMS/*/*.rpm $local_spool") and print "ERROR: could not copy rpm files frpm $chroot/home/builder/rpm/RPMS/ to $local_spool ($!)\n"; - process_queue() + process_queue(); + exit; } +print "iurt: reprocess generated packages queue\n"; process_queue(); dump_cache(); -print "ERROR: RPM with a wrong SRPM name:\n" if @wrong_rpm; +print "ERROR iurt: RPM with a wrong SRPM name\n" if @wrong_rpm; open my $file, ">$local_spool/log/wrong_srpm_names.log"; foreach (@wrong_rpm) { print $file "$_->[1] -> $_->[0] (", $::rpm_srpm{$_->[1]},")\n"; @@ -290,14 +300,20 @@ sub usage { } sub process_queue { - my $dir = "$local_home/$distro_tag/$my_arch"; + my $dir = "$local_home/iurt/$distro_tag/$my_arch"; #my $dir = "$base_dir/RPMS/"; opendir my $rpmdir, $dir; foreach my $rpm (readdir $rpmdir) { - my ($rarch, $srpm) = update_srpm($dir, $rpm) or next; + my ($rarch, $srpm) = update_srpm($dir, $rpm); + $rarch or next; # try to keep the opportunity to prevent disk full - system("mv $dir/$rpm $base_dir/RPMS/") and next; + my $ok = copy "$dir/$rpm", "$base_dir/RPMS/"; + if (!$ok){ + print "ERROR process_queue: cannot copy $dir/$rpm to $base_dir/RPMS/ ($!)\n"; + next + } + unlink "$dir/$rpm"; $::queue->{$srpm}{$rarch} = 1 } closedir $rpmdir; @@ -319,11 +335,11 @@ sub update_srpm { sub dump_cache { my $filename = $cache; - open my $file, ">$filename.tmp" or die "FATAL dump_cache: cannot open $filename.tmp"; + open my $file, ">$filename.tmp" or die "FATAL iurt dump_cache: cannot open $filename.tmp"; flock($file,LOCK_EX); seek($file, 0, 2); $Data::Dumper::Indent = 1; - print $file Data::Dumper->Dump([ $::rpm_srpm, $::failure, $::queue, $::warning ], [ "::rpm_srpm", "::failure", "::queue", "::warning" ]); + print $file Data::Dumper->Dump([ $::rpm_srpm, $::failure, $::queue, $::warning, $::run ], [ "::rpm_srpm", "::failure", "::queue", "::warning", "::run" ]); print $file "1"; unlink $filename; link "$filename.tmp", $filename; @@ -376,43 +392,44 @@ sub fix_srpm_name { } sub perform_command { - my ($command, $mail, $error, $hash, $die, $timeout, $cc, $log, $freq) = @_; - $timeout ||= 300; - $freq ||= 24; - print "Timeout $timeout\n"; + my ($command, %opt) = @_; + # my ($command, $mail, $error, $hash, $die, $timeout, $cc, $log, $freq) = @_; + $opt{timeout} ||= 300; + $opt{freq} ||= 24; + print "Timeout $opt{timeout}\n"; my $p_pid = $$; my $pid = fork; my $stat; if ($pid) { print "$command\n"; my $output; - $::warning->{$hash}{$my_arch}{$mail}++; - if ($log) { - $output = `$command 2>&1 | tee $log/$hash.$::warning->{$hash}{$my_arch}{$mail}.log`; + if ($opt{log}) { + $output = `$command 2>&1 | tee $opt{log}/$opt{hash}.$run.log`; } else { $output = `$command 2>&1`; } # FIXME process goes in defunct always, kill -14 should unsleep it, but not kill 9, $pid; if ($?) { - if ($mail) { - if ($::warning->{$hash}{$my_arch}{$mail} % $freq) { - sendmail($mail, $cc , $error , $output, 0, 0); + if ($opt{mail}) { + if ($::warning->{$opt{hash}}{$my_arch}{$opt{mail}} % $opt{freq}) { + sendmail($opt{mail}, $opt{cc} , $opt{error} , $output, 0, 0); } else { - sendmail('warly@mandriva.com', '' , $error, $output, 0, 0); + sendmail('warly@mandriva.com', '' , $opt{error}, $output, 0, 0); } } + $::warning->{$opt{hash}}{$my_arch}{$opt{mail}}++; print $output; - die "FATAL iurt: $error." if $die; + die "FATAL iurt: $opt{error}." if $opt{die}; return 0 } } else { - my $t = sleep $timeout; + my $t = sleep $opt{timeout}; my ($cmd) = $command =~ s/^sudo //; my $pgrep=`pgrep -f "$cmd"`; - print "PGREP $pgrep timeout $t\n"; - if ($t == $timeout && $pgrep) { - print "\nKilling -9 $cmd\n\n"; + print "iurt: PGREP $pgrep timeout $t\n"; + if ($t == $opt{timeout} && $pgrep) { + print "\niurt: killing -9 $cmd\n\n"; system(qq{sudo pkill -9 -u root -f "$cmd"}); } exit |