aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mageia.org>2023-12-31 21:04:09 +0000
committerPascal Terjan <pterjan@mageia.org>2024-01-01 18:04:29 +0000
commitdece1249cfdf070c7f7fdd8e4eee099436d87ead (patch)
treece37185d43bdec8196bd7de1bc937e5ed6bf0118 /lib
parent12b6bc689028cf3faff28f5a8d43da1c3c782fec (diff)
downloadiurt-dece1249cfdf070c7f7fdd8e4eee099436d87ead.tar
iurt-dece1249cfdf070c7f7fdd8e4eee099436d87ead.tar.gz
iurt-dece1249cfdf070c7f7fdd8e4eee099436d87ead.tar.bz2
iurt-dece1249cfdf070c7f7fdd8e4eee099436d87ead.tar.xz
iurt-dece1249cfdf070c7f7fdd8e4eee099436d87ead.zip
Add an utility to cancel a build
Usage: $ cancel_build 20231231211004.pterjan.duvel.1487312 *: [cancel_build] check uploads tree I: [cancel_build] check dir: /var/lib/schedbot/uploads/done I: [cancel_build] check dir: /var/lib/schedbot/uploads/todo I: [cancel_build] Failing 20231231211004.pterjan.duvel.1487312 and cleaning up done architectures I: [cancel_build] Killing process 1146007 on rabbit2 (building for arch "i586") I: [cancel_build] Killing process 2204767 on ecosse0 (building for arch "x86_64") I: [cancel_build] Killing process 3092253 on ociaa1-a (building for arch "aarch64") I: [cancel_build] Killing process 3092165 on ociaa1-b (building for arch "armv7hl")
Diffstat (limited to 'lib')
-rw-r--r--lib/Iurt/Process.pm25
-rwxr-xr-xlib/Iurt/Ulri.pm138
2 files changed, 158 insertions, 5 deletions
diff --git a/lib/Iurt/Process.pm b/lib/Iurt/Process.pm
index ea90a62..c234d0b 100644
--- a/lib/Iurt/Process.pm
+++ b/lib/Iurt/Process.pm
@@ -15,6 +15,7 @@ our @EXPORT = qw(
check_pid
perform_command
sudo
+ wait_for_lock
);
my $sudo = '/usr/bin/sudo';
@@ -23,6 +24,7 @@ my $sudo = '/usr/bin/sudo';
Check that there is no other program running and create a pidfile lock
I<$run> current running options
+I<$exit> whether to exit when the lock is in use
Return true.
=cut
@@ -31,7 +33,7 @@ Return true.
# should be designed
sub check_pid {
- my ($run) = @_;
+ my ($run, $exit) = @_;
my $pidfile = "$run->{pidfile_home}/$run->{pidfile}";
@@ -66,9 +68,10 @@ sub check_pid {
sleep 1;
}
} else {
- plog('WARN', "another instance [$pid] is already running for ",
- time()-$time, " seconds");
- exit();
+ plog('WARN', "another instance [$pid] is already running for",
+ time()-$time, "seconds");
+ exit() if $exit;
+ return;
}
} else {
plog('WARN', "cleaning stale lockfile");
@@ -81,6 +84,20 @@ sub check_pid {
$pidfile;
}
+sub wait_for_lock {
+ my ($run) = @_;
+
+ plog('INFO', 'Waiting for ulri lock to be available');
+ my $delay = 10;
+ my $pidfile = check_pid($run, 0);
+ while (!defined($pidfile)) {
+ plog('WARN', "waiting $delay seconds before retrying");
+ sleep $delay;
+ $pidfile = check_pid($run, 0);
+ }
+
+ $pidfile;
+}
sub fork_to_monitor {
my ($run, $config, $logfile, %opt) = @_;
diff --git a/lib/Iurt/Ulri.pm b/lib/Iurt/Ulri.pm
index e9f8e44..09be6b0 100755
--- a/lib/Iurt/Ulri.pm
+++ b/lib/Iurt/Ulri.pm
@@ -3,19 +3,155 @@ package Iurt::Ulri;
use base qw(Exporter);
use File::Path qw(make_path);
use File::Temp qw(mktemp);
-use Iurt::Config qw(get_author_email);
+use Iurt::Config qw(config_init config_usage get_author_email);
use Iurt::File qw(check_file_timeout);
use Iurt::Mail qw(sendmail);
use Iurt::Util qw(plog ssh_setup sget ssh sput);
use File::Slurp qw(read_file);
+use MDK::Common qw(cat_);
use strict;
our @EXPORT = qw(
build_package
fetch_logs_and_cleanup
+ load_config
warn_about_failure
);
+sub load_config {
+ my ($run) = @_;
+ my $HOME = $ENV{HOME};
+ my $configfile = "$HOME/.upload.conf";
+ my $sysconfigfile = "/etc/iurt/upload.conf";
+
+ my $config = {};
+ foreach my $f ($configfile, $sysconfigfile) {
+ plog('DEBUG', "load config: $f");
+ if (-f $f) {
+ $config = eval(cat_($f))
+ or die "FATAL $run->{program_name}: syntax error in $f";
+ last;
+ }
+ }
+
+ my %config_usage = (
+ admin => {
+ desc => 'mail address of the bot administrator',
+ default => 'distrib-admin@mandrivalinux.org'
+ },
+ 'arch_translation' => {
+ desc => "Renaming of arch",
+ default => { 'sparc64' => 'sparcv9' }
+ },
+ bot => {
+ desc => "List of bot able to compile the packages",
+ default => {
+ i586 => {
+ localhost => {
+ iurt => {
+ user => 'builder',
+ command => qq(iurt --copy_srpm --group --config local_spool /home/builder/iurt/__DIR__ --no_rsync --chrooted-urpmi -m __MEDIA__ -- http://localhost/distrib/ -p "__PACKAGER__" -r __TARGET__ __ARCH__),
+ packages => '/home/builder/iurt/',
+ },
+ },
+ },
+ },
+ },
+ media => {
+ desc => 'Corresponding media to add given the current media',
+ default => {
+ default => {
+ "core/backports" => [ "core/backports", "core/release", "core/updates" ],
+ "core/backports_testing" => [
+ "core/backports", "core/backports_testing",
+ "core/release", "core/updates"
+ ],
+ "core/release" => [ "core/release" ],
+ "core/updates" => [ "core/release", "core/updates" ],
+ "core/updates_testing" => [
+ "core/release", "core/updates", "core/updates_testing"
+ ],
+ "nonfree/backports" => [
+ "core/backports", "core/release", "core/updates",
+ "nonfree/backports", "nonfree/release", "nonfree/updates"
+ ],
+ "nonfree/backports_testing" => [
+ "core/backports", "core/backports_testing",
+ "core/release", "core/updates",
+ "nonfree/backports", "nonfree/backports_testing",
+ "nonfree/release", "nonfree/updates"
+ ],
+ "nonfree/release" => [ "core/release", "nonfree/release" ],
+ "nonfree/updates" => [
+ "core/release", "core/updates",
+ "nonfree/release", "nonfree/updates"
+ ],
+ "nonfree/updates_testing" => [
+ "core/release", "core/updates", "core/updates_testing",
+ "nonfree/release", "nonfree/updates", "nonfree/updates_testing"
+ ],
+ "tainted/backports" => [
+ "core/backports", "core/release", "core/updates",
+ "tainted/backports", "tainted/release", "tainted/updates"
+ ],
+ "tainted/backports_testing" => [
+ "core/backports", "core/backports_testing",
+ "core/release", "core/updates",
+ "tainted/backports", "tainted/backports_testing",
+ "tainted/release", "tainted/updates"
+ ],
+ "tainted/release" => [ "core/release", "tainted/release" ],
+ "tainted/updates" => [
+ "core/release", "core/updates",
+ "tainted/release", "tainted/updates"
+ ],
+ "tainted/updates_testing" => [
+ "core/release", "core/updates", "core/updates_testing",
+ "tainted/release", "tainted/updates", "tainted/updates_testing"
+ ],
+ },
+ },
+ },
+ faildelay => {
+ desc => "Time after which the rebuild is considered as a failure",
+ default => 36000
+ },
+ http_queue => {
+ desc => 'Address where log can be consulted',
+ default => 'http://pkgsubmit.mageia.org/uploads/'
+ },
+ queue => {
+ desc => "Root of the tree where the packages to compile are located",
+ default => "$HOME/uploads"
+ },
+ tmp => {
+ desc => "Temporary directory",
+ default => "$HOME/tmp"
+ },
+ ssh_options => {
+ desc => "SSH options",
+ default => "-o ConnectTimeout=5 -o BatchMode=yes -o ServerAliveInterval=5"
+ },
+ packager => {
+ desc => 'Default packager tag user by bot',
+ default => 'Mageia Team <http://www.mageia.org>'
+ },
+ 'arch' => {
+ desc => 'Architectures list for each target',
+ default => {
+ default => [ 'i586', 'x86_64' ],
+ },
+ },
+ 'backoff_delays' => {
+ desc => 'List of delays in seconds before retrying retriable errors. Error becomes permanent after reaching the end of the list.',
+ default => [5*60, 30*60, 60*60, 120*60]
+ },
+ );
+ config_usage(\%config_usage, $config) if $run->{config_usage};
+ config_init(\%config_usage, $config, $run);
+ return $config;
+}
+
sub build_package {
my ($config, $pkg_tree, $media, $prefix, $host, $arch, $bot) = @_;