source: trunk/MagicSoft/Mars/datacenter/scripts/jobmanager@ 7946

Last change on this file since 7946 was 7946, checked in by Daniela Dorner, 19 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 4.2 KB
Line 
1#!/bin/sh
2#
3# ========================================================================
4#
5# *
6# * This file is part of MARS, the MAGIC Analysis and Reconstruction
7# * Software. It is distributed to you in the hope that it can be a useful
8# * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
9# * It is distributed WITHOUT ANY WARRANTY.
10# *
11# * Permission to use, copy, modify and distribute this software and its
12# * documentation for any purpose is hereby granted without fee,
13# * provided that the above copyright notice appear in all copies and
14# * that both that copyright notice and this permission notice appear
15# * in supporting documentation. It is provided "as is" without express
16# * or implied warranty.
17# *
18#
19#
20# Author(s): Daniela Dorner 05/2006 <mailto:dorner@astro.uni-wuerzburg.de>
21#
22# Copyright: MAGIC Software Development, 2000-2006
23#
24#
25# ========================================================================
26#
27# This a script, which launches other scripts (all scripts, that are run
28# on primary basis
29#
30
31
32source `dirname $0`/sourcefile
33printprocesslog "INFO starting $0"
34
35set -C
36
37echo "" >> $jmscriptlog 2>&1
38echo "starting jobmanager ("`date`")" >> $jmscriptlog 2>&1
39makedir $jmlogpath
40makedir $listpath >> $jmscriptlog 2>&1
41makedir $lockpath >> $jmscriptlog 2>&1
42
43prev=$max
44user=`whoami`
45notcount=0
46while (( $notcount < 100 ))
47do
48 for (( i=0 ; i < ${#scripts[@]} ; i++ ))
49 do
50 makedir $jmlogpath
51 date >> $jmscriptlog 2>&1
52 echo "sleeping $sleeptime..." >> $jmscriptlog 2>&1
53 sleep $sleeptime
54 dayofweek=`date +%u`
55 hour=`date +%k`
56 source `dirname $0`/sourcefile
57 echo "script: ${scripts[$i]}" >> $jmscriptlog 2>&1
58# echo " day: $dayofweek hour: $hour" >> $jmscriptlog 2>&1
59 queued=`/usr/local/bin/condor_q -global -format "%s\n" Owner | grep -c $user`
60 queued=`setzero $queued`
61 queuedscript=`/usr/local/bin/condor_q -global | grep $user | grep -c ${scripts[$i]}`
62 queuedscript=`setzero $queuedscript`
63 runningscript=`/usr/local/bin/condor_q -global | grep $user | grep ' R ' | grep -c ${scripts[$i]}`
64 runningscript=`setzero $runningscript`
65 stillinqueue=`echo $queuedscript - $runningscript | bc `
66
67 totalpno=${pnototal[$hour]}
68
69 #choose array according to the day of the week
70 case $dayofweek in
71 0 | 6) pnos=( ${pnoswe[@]} ) ;;
72 *) pnos=( ${pnosweek[@]} ) ;;
73 esac
74 num=`echo "((( $i + 1 ) * 24 ) + ( $hour + 1 ) ) - 24 - 1 " | bc `
75 pnoscript=${pnos[$num]}
76 if [ $prev -eq 0 ]
77 then
78 echo " prev=0 => resetting pnoscript [$pnoscript] to max [$max]" >> $jmscriptlog 2>&1
79 pnoscript=$max
80 fi
81 echo " found $queued jobs in the queue (incl. running jobs) [allowed $totalpno]" >> $jmscriptlog 2>&1
82 echo " found $queuedscript ${scripts[$i]} in the queue (incl. running jobs [$runningscript]) [allowed $pnoscript] - not running: $stillinqueue" >> $jmscriptlog 2>&1
83
84 if [ "$queued" -gt "$totalpno" ]
85 then
86 cont >> $jmscriptlog 2>&1
87 else
88 if [ "$queuedscript" -gt "$pnoscript" ]
89 then
90 cont >> $jmscriptlog 2>&1
91 fi
92 fi
93
94 # check if there's something to do
95 getstatus >> $jmscriptlog 2>&1
96 echo " $numproc ${scripts[$i]} still do to" >> $jmscriptlog 2>&1
97 if [ "$numproc" = "" ]
98 then
99 prev=0
100 cont >> $jmscriptlog 2>&1
101 fi
102 prev=$max
103 if [ $numproc -lt $stillinqueue ]
104 then
105 echo " numproc($numproc) -lt stillinqueue($stillinqueue)" >> $jmscriptlog 2>&1
106 cont >> $jmscriptlog 2>&1
107 fi
108
109 date=`date +%Y-%m-%d`
110 echo " committing 1 ${scripts[$i]} to condor" >> $jmscriptlog 2>&1
111 if ! /usr/local/bin/condor_submit -a path=$scriptspath -a prog=${scripts[$i]} -a date=$date -a dir=$runlogpath $scriptspath/run.condor 2>> $jmerrorlog
112 then
113 date >> $jmerrorlog
114 nail -s 'condor problem' $erradrs < $jmerrorlog
115 echo "condor is not working -> sleeping $errorsleeptime" >> $jmscriptlog 2>&1
116 printprocesslog "ERROR submitting ${scripts[$i]} to condor failed"
117 sleep $errorsleeptime
118 fi
119 date >> $jmscriptlog 2>&1
120 echo "" >> $jmscriptlog 2>&1
121 done
122done
123
Note: See TracBrowser for help on using the repository browser.