aboutsummaryrefslogtreecommitdiffstats
path: root/cancel_build
blob: 817dfb2ae240d4f590df6813a6c2cd63d4893d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/perl
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#

use strict;
use MDK::Common qw(cat_);
use Iurt::Config qw(config_usage get_date config_init);
use Iurt::File qw(create_file);
use Iurt::Process qw(wait_for_lock);
use Iurt::Queue qw(cleanup_failed_build get_upload_tree_state load_lock_file_data);
use Iurt::Util qw(plog_init plog ssh_setup ssh);
use Iurt::Ulri qw(load_config);

my %run;
my $program_name = 'cancel_build';
$run{program_name} = $program_name;

my $LOG;
if (!$ENV{ULRI_LOG_FILE} || !open($LOG, '>>', $ENV{ULRI_LOG_FILE})) {
    open($LOG, ">&STDERR");
}

plog_init($program_name, $LOG, 7, 1);
my $prefix = shift or die "Usage: $0 <prefix>\n";

my $HOME = $ENV{HOME};
my $configfile = "$HOME/.upload.conf";
my $sysconfigfile = "/etc/iurt/upload.conf";

my $config = load_config(\%run);

$run{pidfile_home} = $config->{tmp};
# Use ulri lock as we don't want to run concurrently with it
$run{pidfile} = 'ulri';
my $pidfile = wait_for_lock(\%run);

my ($fulldate, $daydate) = get_date();
$run{daydate} = $daydate;

($fulldate, $daydate) = get_date();

my $todo = "$config->{queue}/todo";
my $failure = "$config->{queue}/failure";
my $done = "$config->{queue}/done";
my $reject = "$config->{queue}/reject";

my %pkg_tree = get_upload_tree_state($config);

if (!defined($pkg_tree{$prefix})) {
    plog('ERROR', "Unknown prefix $prefix");
    unlink $pidfile;
    exit 1;
}

my $ent = $pkg_tree{$prefix};
foreach my $media (keys %{$ent->{media}}) {
    foreach my $bot (@{$ent->{media}{$media}{bot}}) {
	$run{bot}{$bot->{host}}{$bot->{bot}} = $prefix;
    }
}

foreach my $media (keys %{$ent->{media}}) {
    my $path = $ent->{media}{$media}{path};
    my $user = $ent->{user};

    # Local pathnames
    my $done_dir = "$done/$path";
    my $todo_dir = "$todo/$path";
    my $fail_dir = "$failure/$path";

    # Calling with "noarch" to make it always a fatal failure
    plog('INFO', "Failing $prefix and cleaning up done architectures");
    cleanup_failed_build($todo_dir, $done_dir, $fail_dir, $prefix, $ent, $media, "noarch", $config);
    foreach my $bot_list (@{$ent->{media}{$media}{bot}}) {
	my ($bot, $host, $date, $pid, $arch, $time) =
		    @$bot_list{qw(bot host date pid arch time)};

	my $bot_conf = $config->{bot}{$arch}{$host}{$bot};
        my $remote = ssh_setup($config->{ssh_options},
			   $bot_conf->{user}, $host);

	my $prefix_dir = "$bot_conf->{packages}/$path/$prefix-$arch/";

	# If our build is noarch, set arch appropriately.
	#
	my $lock_file =
	    "$todo_dir/${prefix}_$arch-noarch.$bot.$host.$date.$pid.lock";

	if (-f $lock_file) {
	    plog('DEBUG', "$prefix is noarch");
	    $arch = "noarch";
	} else {
	    $lock_file =~ s/-noarch//;
	}

	plog('INFO', "Killing process $pid on $host (building for arch \"$arch\")");
	ssh($remote, "kill -TERM $pid");
	$pkg_tree{$prefix}{media}{$media}{cancelled_arch}{$arch} = 1;
	create_file("$done_dir/${prefix}_$arch.cancelled", "$bot $host");
    }
}

unlink $pidfile;