-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbkill_pipe
executable file
·78 lines (61 loc) · 1.52 KB
/
bkill_pipe
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
#!/usr/bin/env perl
=head1 Description
This script sends bstop and bkill commands to all jobs
running in a given pipeline. Since it uses a simple
regex match on a 'bjobs -w' command, it is quite flexible
e.g. bkill_pipe epo_primates_95
=cut
use warnings;
use strict;
use Getopt::Long;
$|++; # turn on auto-flush of stdout buffer
my ( $help, $dry_run );
GetOptions(
"help" => \$help,
"dry_run!" => \$dry_run,
);
die &helptext if ( $help || !$ARGV[0] );
my $search_term = $ARGV[0];
my @all_bjobs = `bjobs -w`;
my @candidates;
foreach my $job ( @all_bjobs ) {
chomp $job;
push( @candidates, $job ) if $job =~ /$search_term/;
}
if (scalar @candidates == 0) {
print "No '$search_term' jobs found!\n";
exit(1);
}
if ( $dry_run ) {
print join("\n", @candidates) . "\n";
exit 0;
}
my %stop_cmds;
my %kill_cmds;
foreach my $kill_job ( @candidates ) {
$kill_job =~ /^(\d+)/;
my $jid = $1;
die "Cannot get job id from '$kill_job'\n" unless $jid;
$stop_cmds{"bstop $jid"} = 1 if $kill_job =~ /RUN/;
$kill_cmds{"bkill $jid"} = 1;
}
# print join("\n", keys %stop_cmds) . "\n\n";
# print join("\n", keys %kill_cmds) . "\n\n";
if ( scalar(keys %stop_cmds) > 0 ) {
system( join('; ', keys %stop_cmds) . ';' );
# allow LSF time to stop jobs
print 'Waiting for jobs to stop';
foreach my $x ( 1..5 ) {
print '.';
sleep 2;
}
print "\n";
}
system( join('; ', keys %kill_cmds) . ';' );
sub helptext {
my $msg = <<HELPEND;
bkill_pipe <hive_pipeline_name> : kill all jobs in the given pipeline
Usage:
HELPEND
return $msg;
}