Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 12:45:15

0001 #!/usr/bin/env perl
0002 #     R. Mankel, DESY Hamburg     16-Jul-2007
0003 #     A. Parenti, DESY Hamburg    16-Apr-2008
0004 #     $Revision: 1.3 $
0005 #     $Date: 2009/01/07 18:26:00 $
0006 #
0007 #  Kill all jobs being processed by ZARAH,
0008 #  i.e. those pending, running or suspended.
0009 #
0010 #  This is useful in case an error has been detected.
0011 #  The killed jobs go to FAIL status.
0012 #  They can be rescheduled with mps_retry.pl once the
0013 #  problem has been fixed.
0014 #  
0015 #
0016 #  Usage:
0017 #      mps_kill.pl
0018 #
0019 
0020 BEGIN {
0021 use File::Basename;
0022 unshift(@INC, dirname($0)."/mpslib");
0023 }
0024 use Mpslib;
0025 
0026 @MODSTATES = ();
0027 @MODJOBS = ();
0028 $killAll = 0;
0029 $killMerge = 0;
0030 
0031 # parse the arguments
0032 while (@ARGV) {
0033   $arg = shift(ARGV);
0034   if ($arg =~ /\A-/) {  # check for option 
0035     if ($arg =~ "h") {
0036       $helpwanted = 1;
0037     }
0038     elsif ($arg =~ "a") {
0039       $killAll = 1;
0040     }
0041     elsif ($arg =~ "m") {
0042       $killMerge = 1;
0043     }
0044     $optionstring = "$optionstring$arg";
0045   }
0046   else {                # parameters not related to options
0047     $i = $i + 1;
0048     if (($arg =~ m/\d+/) eq 1) {
0049       print "Parameter $arg interpreted as job number\n";
0050       push @MODJOBS,$arg;
0051     }
0052     elsif (($arg =~ m/[A-Z]+/) eq 1) {
0053       print "Parameter $arg interpreted as job state\n";
0054       push @MODSTATES,$arg;
0055     }
0056     else {
0057       print "Parameter $arg not recognized\n";
0058     }
0059   }
0060 }
0061 
0062 
0063 
0064 read_db();
0065 
0066 if ($killAll == 1) {
0067   # loop over pending, running or suspended jobs
0068   for ($i=0; $i<@JOBID; ++$i) {
0069     if (@JOBSTATUS[$i] =~ /PEND/
0070     or @JOBSTATUS[$i] =~ /RUN/
0071     or @JOBSTATUS[$i] =~ /SUSP/) {
0072       system "bkill @JOBID[$i]";
0073       print "bkill @JOBID[$i]\n";
0074       my $disabled = "";
0075       $disabled = "DISABLED" if( $JOBSTATUS[$i] =~ /DISABLED/gi);
0076       @JOBSTATUS[$i] = $disabled."FAIL";
0077       @JOBHOST[$i] = "user kill";
0078     }
0079   }
0080 }
0081 else {
0082   # only kill certain job numbers or states
0083   for ($i=0; $i<@JOBID; ++$i) {
0084     if (@JOBSTATUS[$i] =~ /PEND/
0085     or @JOBSTATUS[$i] =~ /RUN/
0086     or @JOBSTATUS[$i] =~ /SUSP/) {
0087       my $disabled = "";
0088       $disabled = "DISABLED" if( $JOBSTATUS[$i] =~ /DISABLED/gi);
0089       $JOBSTATUS[$i] =~ s/DISABLED//gi;
0090       $stateText = "^@JOBSTATUS[$i]\$";
0091       $theNum = $i + 1;
0092       $jobText = "^$theNum\$";
0093       if ( ( (grep /$stateText/,@MODSTATES) > 0) || (grep /$jobText/,@MODJOBS) > 0) {
0094     print "bkill @JOBID[$i]\n";
0095     system "bkill @JOBID[$i]";
0096     @JOBSTATUS[$i] = $disabled."FAIL";
0097     @JOBHOST[$i] = "user kill";
0098       }
0099     }
0100   }
0101 }
0102 if ($killMerge eq 1) {
0103     $i = @JOBID - 1;
0104     if (@JOBSTATUS[$i] eq "PEND"
0105         or @JOBSTATUS[$i] eq "RUN"
0106         or @JOBSTATUS[$i] eq "SUSP") {
0107         $stateText = "^@JOBSTATUS[$i]\$";
0108         $theNum = $i + 1;
0109         $jobText = "^$theNum\$";
0110         if ( ( (grep /$stateText/,@MODSTATES) > 0) || (grep /$jobText/,@MODJOBS) > 0) {
0111 
0112         print "bkill @JOBID[$i]\n";
0113         system "bkill @JOBID[$i]";
0114         @JOBSTATUS[$i] = "FAIL";
0115         @JOBHOST[$i] = "user kill";
0116         }
0117     }
0118 }
0119 write_db();