aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorent Villard <warly@mandriva.com>2006-01-31 12:59:31 +0000
committerFlorent Villard <warly@mandriva.com>2006-01-31 12:59:31 +0000
commit9e5186390c61df90a72ee042e55d6fe34db24359 (patch)
treef727ce100e215b1d1f5d721279c8c56e5755ab3e
parente9b34c31126c75170187be60a176dd68c2d00d4b (diff)
downloadiurt-9e5186390c61df90a72ee042e55d6fe34db24359.tar
iurt-9e5186390c61df90a72ee042e55d6fe34db24359.tar.gz
iurt-9e5186390c61df90a72ee042e55d6fe34db24359.tar.bz2
iurt-9e5186390c61df90a72ee042e55d6fe34db24359.tar.xz
iurt-9e5186390c61df90a72ee042e55d6fe34db24359.zip
add a verbose level to filter messages
-rwxr-xr-xiurt268
1 files changed, 37 insertions, 31 deletions
diff --git a/iurt2 b/iurt2
index 727ff6f..7222dc4 100755
--- a/iurt2
+++ b/iurt2
@@ -106,9 +106,12 @@ $run{todo} = [ ];
[ "", "no_rsync", 0, "",
"Do not send build log to the distant rsync server",
sub { $run{no_rsync} = 1 }, "Setting the no rsync warn flag" ],
+ [ "v", "verbose", 1, "<verbose level>",
+ "Give more info messages about what is going on (level from 1 to 10)",
+ sub { $run{verbose} = $_[0]; 1 }, "Setting verbose level" ],
[ "w", "warn", 0, "",
"Warn maintainer of the packages about problem in the rebuild",
- sub { $run{warn} = @_; 1 }, "Setting warn flag to warn maintainers" ],
+ sub { $run{warn} = 1 ; 1 }, "Setting warn flag to warn maintainers" ],
[ "d", "dir", -1, "",
"Directory where to find packages to rebuild",
sub { $run{extra_dir} = @_; 1 }, "Adding extra source packages directories" ],
@@ -120,7 +123,7 @@ $run{LOG} = $LOG;
my $todo = parseCommandLine("$program_name", \@ARGV, \@params);
@ARGV and usage("$program_name", \@params, "@ARGV, too many arguments");
foreach my $t (@$todo) {
- print {$run{LOG}} "$program_name: $t->[2]\n";
+ print {$run{LOG}} "$program_name: $t->[2]\n" if $run{verbose} > 5;
&{$t->[0]}(@{$t->[1]}) or print {$run{LOG}} "ERROR: $t->[2]\n";
}
@@ -140,7 +143,7 @@ my %arch_comp = (
my $HOME = $ENV{HOME};
my $configfile = "$HOME/.iurt.$run{distro_tag}.conf";
-print {$run{LOG}} "iurt: loading config file $configfile\n";
+print {$run{LOG}} "iurt: loading config file $configfile\n" if $run{verbose} > 1;
my $config;
if (-f $configfile) {
$config = do $configfile or die "FATAL iurt: syntax error in $configfile";
@@ -206,7 +209,7 @@ if ($run{chroot}) {
my $cachefile = "$config->{cache_home}/iurt.$run{distro_tag}.$run{my_arch}.cache";
my $cache;
if (-f $cachefile && $run{cache}) {
- print {$run{LOG}} "iurt: loading cache file $cachefile\n";
+ print {$run{LOG}} "iurt: loading cache file $cachefile\n" if $run{verbose} > 1;
$cache = do $cachefile
} else {
$cache = { rpm_srpm => {}, failure => {}, queue => {}, warning => {}, run => 1, needed => {}, no_unionfs => {} }
@@ -224,7 +227,7 @@ if (!@{$run{todo}} && !$run{debug}) {
unlink $run{pidfile} if $run{pidfile};
exit
}
-print {$run{LOG}} "iurt: will try to compile $to_compile packages\n";
+print {$run{LOG}} "iurt: will try to compile $to_compile packages\n" if $run{verbose} > 1;
exit if !$run{rebuild};
@@ -284,14 +287,14 @@ foreach (my $i ; $i < @{$run{todo}}; $i++) {
# FIXME unfortunately urpmi stalls quite often
retry:
my $match = "urpmi $urpmi_options --root $chroot";
- if (!clean_process($match)) {
+ if (!clean_process($match, $run{verbose})) {
dump_cache();
die "FATAL iurt: Could not have urpmi working !"
}
if ($unionfs_tmp) {
my $mount_point = "$unionfs_dir/unionfs.$run{run}.$union_id";
- print {$run{LOG}} "Cleaning $mount_point\n";
- if (!clean_mnt($mount_point)) {
+ print {$run{LOG}} "Cleaning $mount_point\n" if $run{verbose} > 1;
+ if (!clean_mnt($mount_point, $run{verbose})) {
dump_cache();
die "FATAL iurt: could not kill remaining processes acceding $mount_point"
}
@@ -315,7 +318,7 @@ retry:
system("sudo mount -t proc none $chroot/proc") and die "FATAL iurt: could not mount /proc in the chroot $chroot.";
}
} else {
- print {$run{LOG}} "iurt: installing a new chroot for $srpm in $chroot\n";
+ print {$run{LOG}} "iurt: installing a new chroot for $srpm in $chroot\n" if $run{verbose} > 1;
clean_chroot($chroot, \%run)
}
my ($srpm_name) = $srpm =~ /(.*)-[^-]+-[^-]+\.src\.rpm$/ or next;
@@ -332,7 +335,7 @@ retry:
#($maintainer, $cc) = ($config->{admin},'');
# recreate a new srpm for buildarch condition in the spec file
- print {$run{LOG}} "Copying $srpm to $chroot\n";
+ print {$run{LOG}} "Copying $srpm to $chroot\n" if $run{verbose} > 1;
perform_command("sudo cp $dir/$srpm $chroot/home/builder/rpm/SRPMS/",
\%run, $config,
mail => $config->{admin},
@@ -351,7 +354,7 @@ retry:
error => "[REBUILD] cannot create $srpm in $chroot",
debug_mail => $run{debug},
hash => "create_$srpm") or next;
- print {$run{LOG}} "Installing build dependencies of $srpm...\n";
+ print {$run{LOG}} "Installing build dependencies of $srpm...\n" if $run{verbose} > 1;
perform_command("sudo urpmi $urpmi_options --root $chroot $chroot/home/builder/rpm/SRPMS/$srpm",
\%run, $config,
@@ -399,7 +402,7 @@ retry:
timeout => 60,
debug_mail => $run{debug},
log => "$local_spool/log/"); # or next; As this failed quite often, do not stop
- print {$run{LOG}} "Compiling $srpm\n";
+ print {$run{LOG}} "Compiling $srpm\n" if $run{verbose} > 1;
if (!perform_command(qq{TMP=/home/builder/tmp/ sudo chroot $chroot /bin/su builder -c "rpm --rebuild /home/builder/rpm/SRPMS/$srpm"},
\%run, $config,
mail => $maintainer,
@@ -462,12 +465,13 @@ retry:
print {$run{LOG}} "iurt: debug mode, skip other packages\n";
exit
} else {
+ print {$run{LOG}} "iurt: build successful, copying packages to $local_spool.\n";
system("cp $chroot/home/builder/rpm/RPMS/*/*.rpm $local_spool") and print {$run{LOG}} "ERROR: could not copy rpm files from $chroot/home/builder/rpm/RPMS/ to $local_spool ($!)\n";
process_queue($config, \%run, \@wrong_rpm)
}
}
-print {$run{LOG}} "iurt: reprocess generated packages queue\n";
+print {$run{LOG}} "iurt: reprocess generated packages queue\n" if $run{verbose};
process_queue($config, \%run, \@wrong_rpm);
dump_cache();
@@ -486,7 +490,7 @@ if ($config->{rsync_to} && !$run{no_rsync}) {
}
# one last try to clean
-print {$run{LOG}} "iurt: try to clean remaining unionfs\n";
+print {$run{LOG}} "iurt: try to clean remaining unionfs\n" if $run{verbose};
if ($run{unionfs}) {
clean_all_unionfs($unionfs_dir)
}
@@ -511,7 +515,7 @@ sub config_usage {
sub clean_all_unionfs {
my ($unionfs_dir) = @_;
- print {$run{LOG}} "Cleaning old unionfs remaining dir in $unionfs_dir\n";
+ print {$run{LOG}} "Cleaning old unionfs remaining dir in $unionfs_dir\n" if $run{verbose} > 1;
opendir my $dir, $unionfs_dir or die "FATAL iurt: could not open $unionfs_dir ($!)";
foreach (readdir $dir) {
/unionfs\.(\d+)\.(\d+)/ or next;
@@ -523,7 +527,7 @@ sub clean_all_unionfs {
sub clean_chroot {
my ($chroot, $run, $only_clean) = @_;
if (-d $chroot) {
- system("sudo umount $chroot/proc");
+ system("sudo umount $chroot/proc &> /dev/null");
perform_command("sudo rm -rf $chroot",
$run, $config,
mail => $config->{admin},
@@ -548,24 +552,24 @@ sub clean_chroot {
}
sub clean_process {
- my ($match) = @_;
- return clean($match, "pgrep -u root -f", "sudo pkill -9 -u root -f");
+ my ($match, $verbose) = @_;
+ return clean($match, "pgrep -u root -f", "sudo pkill -9 -u root -f", $verbose);
}
sub clean_mnt {
- my ($mount_point) = @_;
- return clean($mount_point, "fuser", "sudo fuser -k");
+ my ($mount_point, $verbose) = @_;
+ return clean($mount_point, "fuser", "sudo fuser -k", $verbose);
}
sub clean {
- my ($var, $cmd, $kill_cmd) = @_;
+ my ($var, $cmd, $kill_cmd, $verbose) = @_;
my $ps;
my $i;
while ($ps = `$cmd "$var"`) {
system(qq{$kill_cmd "$var"});
sleep 1;
$ps =~ s/\n/,/g;
- print {$run{LOG}} "Trying to remove previous blocked processes for $var ($ps)\n";
+ print {$run{LOG}} "Trying to remove previous blocked processes for $var ($ps)\n" if $verbose > 1;
return 0 if $i++ > 10
}
1
@@ -573,8 +577,10 @@ sub clean {
sub clean_unionfs {
my ($unionfs_dir, $run, $union_id) = @_;
- system("sudo umount $unionfs_dir/unionfs.$run.$union_id/proc") and print {$run{LOG}} "ERROR iurt: could not umount /proc in $unionfs_dir/unionfs.$run.$union_id\n";
- print "Cleaning $unionfs_dir/unionfs.$run.$union_id\n";
+ if (system("sudo umount $unionfs_dir/unionfs.$run.$union_id/proc &>/dev/null") && $run{verbose} > 1) {
+ print {$run{LOG}} "ERROR iurt: could not umount /proc in $unionfs_dir/unionfs.$run.$union_id\n"
+ }
+ print "Cleaning $unionfs_dir/unionfs.$run.$union_id\n" if $run{verbose} > 1;
my $nok = 1;
while ($nok) {
foreach my $t ("unionfs",'tmpfs') {
@@ -583,16 +589,16 @@ sub clean_unionfs {
my $last;
while (check_mounted($d, $t)) {
system("sudo fuser -k $d");
- print {$run{LOG}} "iurt: umounting $d\n";
+ print {$run{LOG}} "iurt: umounting $d\n" if $run{verbose} > 2;
if (system(qq{sudo umount $d &> /dev/null})) {
- print {$run{LOG}} "WARNING iurt: could not umount $d ($!)\n";
+ print {$run{LOG}} "WARNING iurt: could not umount $d ($!)\n" if $run{verbose} > 1;
$union_id++;
$last = 1;
last
}
}
$last and last;
- print {$run{LOG}} "iurt: removing $d\n";
+ print {$run{LOG}} "iurt: removing $d\n" if $run{verbose} > 1;
system(qq{sudo rm -rf $d});
$nok = 0
}
@@ -648,7 +654,7 @@ sub process_queue {
my $ok = copy "$dir/$rpm", "$config->{upload}/RPMS/";
# try to keep the opportunity to prevent disk full
if (!$ok){
- print "ERROR process_queue: cannot copy $dir/$rpm to $config->{upload}/RPMS/ ($!)\n";
+ print {$run{LOG}} "ERROR process_queue: cannot copy $dir/$rpm to $config->{upload}/RPMS/ ($!)\n";
next
}
}
@@ -738,7 +744,7 @@ sub perform_command {
my ($command, $run, $config, %opt) = @_;
$opt{timeout} ||= 300;
$opt{freq} ||= 24;
- print "Timeout $opt{timeout}\n";
+ print {$run{LOG}} "Timeout $opt{timeout}\n" if $run{verbose} > 2;
# from alarm perldoc
my $output;
my $kill;
@@ -749,7 +755,7 @@ sub perform_command {
eval {
local $SIG{ALRM} = sub { print "Timeout!\n"; $kill = 1; die "alarm\n" }; # NB: \n required
alarm $opt{timeout};
- print "$command\n";
+ print {$run{LOG}} "$command\n" if $run{verbose} > 2;
if ($opt{log}) {
#$output = `$command 2>&1 2>&1 | tee $opt{log}/$opt{hash}.$run.log`;
system("$command &> $opt{log}/$opt{hash}.$run->{run}.log");
@@ -822,7 +828,7 @@ sub kill_for_good {
sub check_chroot {
my ($chroot, $chroot_tar, $run) = @_;
- print "iurt: checking basesystem tar\n";
+ print {$run{LOG}} "iurt: checking basesystem tar\n" if $run{verbose};
system(qq{sudo pkill -9 -u root -f "urpmi $urpmi_options --root $chroot"});
clean_chroot($chroot, $run, 1) or die "FATAL iurt: Could no prepare initial chroot";
perform_command("sudo $config->{install_chroot_binary} cooker $config->{basesystem_media} $chroot_tar $chroot 501 basesystem tar rpm-build",