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

Last change on this file since 9488 was 9488, checked in by Daniela Dorner, 15 years ago
*** empty log message ***
  • Property svn:executable set to *
File size: 9.4 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-2007
23#
24#
25# ========================================================================
26#
27# This a script, which launches other scripts (all scripts, that are run
28# on primary basis
29#
30
31source `dirname $0`/sourcefile
32printprocesslog "INFO starting $0"
33
34set -C
35
36# function to continue in loop and go to next script
37function nextscript()
38{
39 echo `date +%F\ %T`" sleeping \$$1 = $sleeptime seconds... " >> $jmscriptlog 2>&1
40 sleep $2
41 echo "" >> $jmscriptlog 2>&1
42 continue
43}
44
45echo "" >> $jmscriptlog 2>&1
46echo "" >> $jmscriptlog 2>&1
47echo -n `date +%F\ %T`" starting jobmanager for setup " >> $jmscriptlog 2>&1
48
49# decide which jobmanager you want to run
50# setup of the different jobmanagers (which scripts they start)
51# the number of jobs are defined in the file setup
52case $1 in
53 data) echo -n "'data'" >> $jmscriptlog 2>&1
54 scripts=( "runganymed" "runstar" "runcallisto" ) # not used: "dodatacheck" "cutslices"
55 scriptscolname=( "fGanymed" "fStar" "fCallisto" ) # not used: "fDataCheckDone" "fCompmux"
56 pnosweek=( ${pnoganymed[@]} ${pnostar[@]} ${pnocallisto[@]} ) # not used: ${pnodatacheck[@]} ${pnocutslices[@]}
57 pnoswe=( ${pnoganymedwe[@]} ${pnostarwe[@]} ${pnocallistowe[@]} ) # not used: ${pnodatacheckwe[@]} ${pnocutsliceswe[@]}
58 break
59 ;;
60 mc) echo -n "'mc'" >> $jmscriptlog 2>&1
61 scripts=( "runcorsika" "runreflector" "runcamera" )
62 scriptscolname=( "fCorsikaFileAvail" "fReflectorFileAvail" "fCameraFileAvail" )
63 pnosweek=( ${pnocorsika[@]} ${pnoreflector[@]} ${pnocamera[@]} )
64 pnoswe=( ${pnocorsikawe[@]} ${pnoreflectorwe[@]} ${pnocamerawe[@]} )
65 break
66 ;;
67 ctamc) echo -n "'cta mc'" >> $jmscriptlog 2>&1
68 scripts=( "runsimtel" )
69 scriptscolname=( "fCorsikaSimTelarray" )
70 pnosweek=( ${pnosimtel[@]} )
71 pnoswe=( ${pnosimtelwe[@]} )
72 break
73 ;;
74 *) echo ""
75 echo "'$1' is a wrong commandline option for jobmanager -> exit" >> $jmscriptlog 2>&1
76 echo "'$1' is a wrong commandline option for jobmanager -> exit"
77 printprocesslog "WARN '$1' is a wrong commandline option for jobmanager"
78 finish >> $jmscriptlog 2>&1
79 break
80 ;;
81esac
82
83# choose commands according to queueing system (defined in setup)
84case $queuesys in
85 sge) echo " on queuing system 'sun grid engine'" >> $jmscriptlog 2>&1
86 alias 'queuesubmit'='/opt/gridengine/bin/lx26-amd64/qsub -b y -e `echo $runlogpath`/error-`echo $date`.log -o `echo $runlogpath`/log-`echo $date`.log `echo $scriptspath`/`echo ${scripts[$i]}` '
87# alias 'queuesubmit'='/opt/gridengine/bin/lx26-amd64/qsub -sc runlogpath=`echo $runlogpath` -sc date=`echo $date` -sc scriptspath=`echo $scriptspath` -sc script=`echo ${scripts[$i]}` `echo $scriptspath`/job.sge '
88 alias 'checkqueue'="/opt/gridengine/bin/lx26-amd64/qstat | awk ' { print \"Owner\"\$4\" \" \$3\"Jobstatus\"\$5 } '"
89 break
90 ;;
91 condor) echo " on queuing system 'condor'" >> $jmscriptlog 2>&1
92 alias 'queuesubmit'='/usr/local/bin/condor_submit -a path=`echo $scriptspath` -a prog=`echo ${scripts[$i]}` -a date=`echo $date` -a dir=`echo $runlogpath` `echo $scriptspath`/run.condor'
93 alias 'checkqueue'='/usr/local/bin/condor_q -global -format "Owner%s " Owner -format "%s" CMD -format "Jobstatus%s\n" Jobstatus '
94 break
95 ;;
96 *) echo "" >> $jmscriptlog 2>&1
97 finish >> $jmscriptlog 2>&1
98 ;;
99esac
100
101echo "" >> $jmscriptlog 2>&1
102
103prev=$max
104user=`whoami`
105# endless loop
106notcount=0
107nothingtodocount=0
108nothingtodosleeptime=0
109errorsleeptime=$errorsleeptimedefault
110while (( $notcount < 100 ))
111do
112 for (( i=0 ; i < ${#scripts[@]} ; i++ ))
113 do
114 source `dirname $0`/sourcefile
115 echo `date +%F\ %T`" Evaluating processing status for script '${scripts[$i]}'" >> $jmscriptlog 2>&1
116
117 # check if there's something to do
118 column=${scriptscolname[$i]}
119 getstatus >> $jmscriptlog 2>&1
120 echo `date +%F\ %T`" Database: $numproc ${scripts[$i]} still to be done (incl. idle jobs) [DB/table/column $db/$table/$column]" >> $jmscriptlog 2>&1
121 if [ "$numproc" = "" ]
122 then
123 prev=0
124 nothingtodocount=`expr $nothingtodocount + 1`
125 if [ $nothingtodocount -lt ${#scripts[@]} ]
126 then
127 nextscript 0 0
128 else
129 if [ $nothingtodosleeptime -lt $sleeptimelimit ]
130 then
131 nothingtodosleeptime=`echo " $nothingtodocount * $sleeptime " | bc`
132 fi
133 nextscript nothingtodosleeptime $nothingtodosleeptime
134 fi
135 else
136 nothingtodocount=0
137 nothingtodosleeptime=0
138 fi
139
140 # get processes in queue
141# q=(`/usr/local/bin/condor_q -global -format "Owner%s " Owner -format "%s" CMD -format "Jobstatus%s\n" Jobstatus 2>&1 `)
142# q=(`/opt/gridengine/bin/lx26-amd64/qstat | awk ' { print "Owner"$4" " $3"Jobstatus"$5 } ' 2>&1 `)
143 q=(`checkqueue 2>&1 `)
144 if echo $q | egrep \(Error\|failed\)
145 then
146 echo `date +%F\ %T`" WARN checking query ($queuesys) failed" >> $jmscriptlog 2>&1
147 printprocesslog "WARN checking query ($queuesys) failed"
148 echo `date +%F\ %T`" WARN checking query ($queuesys) failed" >> $jmerrorlog
149 nextscript sleeptime $sleeptime
150 fi
151 # get processes of user in queue
152 q1=(`echo ${q[@]} | egrep -o Owner$user`)
153 queued=${#q1[@]}
154 # get scripts in queue
155 q2=(`echo ${q[@]} | egrep -o ${scripts[$i]}`)
156 queuedscript=${#q2[@]}
157 # get running scripts
158 q3=( `echo ${q[@]} | egrep -o \(${scripts[$i]}Jobstatus2\|${scripts[$i]}Jobstatusr\)` )
159 runningscript=${#q3[@]}
160 stillinqueue=`echo $queuedscript - $runningscript | bc `
161
162 #get total number of allowed process for current time
163 hour=`date +%k`
164 if [ ${pnototal[$hour]} -lt $totalmax ]
165 then
166 totalpno=${pnototal[$hour]}
167 else
168 totalpno=$totalmax
169 fi
170
171 #choose array according to the day of the week
172 dayofweek=`date +%u`
173 case $dayofweek in
174 0 | 6) pnos=( ${pnoswe[@]} ) ;;
175 *) pnos=( ${pnosweek[@]} ) ;;
176 esac
177 # get number of allowed scripts for current time
178 num=`echo "((( $i + 1 ) * 24 ) + ( $hour + 1 ) ) - 24 - 1 " | bc `
179 pnoscript=${pnos[$num]}
180 # if there was nothing to do for previous script, more scripts can be allowed
181 if [ $prev -eq 0 ]
182 then
183 echo `date +%F\ %T`" \$prev=0 => resetting \$pnoscript from $pnoscript to $max [\$max]" >> $jmscriptlog 2>&1
184 pnoscript=$max
185 fi
186 echo `date +%F\ %T`" queue for user '$user': total: $queued queued jobs [allowed \$totalpno = $totalpno]" >> $jmscriptlog 2>&1
187 echo `date +%F\ %T`" queue for user '$user': ${scripts[$i]}: $queuedscript queued, $runningscript running, $stillinqueue idle [allowed \$pnoscript = $pnoscript]" >> $jmscriptlog 2>&1
188
189 # continue if there are already enough processes or scripts in the queue
190 if [ "$queued" -ge "$totalpno" ] || [ "$queuedscript" -ge "$pnoscript" ]
191 then
192 nextscript sleeptime $sleeptime
193 fi
194 # continue if the number of script is the queue is larger (or equal) than the number which still has to be done
195 if [ $numproc -le $stillinqueue ]
196 then
197 echo `date +%F\ %T`" \$numproc ($numproc) < \$stillinqueue ($stillinqueue) " >> $jmscriptlog 2>&1
198 nextscript sleeptime $sleeptime
199 fi
200
201 # reset prev
202 prev=$max
203
204 # submit 1 script to queuing system
205 date=`date +%Y-%m-%d`
206 echo `date +%F\ %T`" committing 1 ${scripts[$i]} to $queuesys" >> $jmscriptlog 2>&1
207# if ! /usr/local/bin/condor_submit -a path=$scriptspath -a prog=${scripts[$i]} -a date=$date -a dir=$runlogpath $scriptspath/run.condor 2>> $jmerrorlog
208# if ! /opt/gridengine/bin/lx26-amd64/qsub -e $runlogpath/error-$date.log -o $runlogpath/log-$(date).log 2>> $jmerrorlog
209 if ! queuesubmit 2>> $jmerrorlog
210 then
211 echo `date`" WARN submitting job ($queuesys) failed" >> $jmerrorlog
212 echo `date +%F\ %T`" WARN $queuesys is not working -> sleeping $errorsleeptime [\$errorsleeptime]" >> $jmscriptlog 2>&1
213 printprocesslog "WARN submitting ${scripts[$i]} ($queuesys) failed"
214 if [ $errorsleeptime -lt $sleeptimelimit ]
215 then
216 errorsleeptime=`echo " $errorsleeptime + $errorsleeptimedefault " | bc`
217 fi
218 nextscript errorsleeptime $errorsleeptime
219 else
220 errorsleeptime=$errorsleeptimedefault
221 fi
222 nextscript sleeptime $sleeptime
223 done
224done
225
Note: See TracBrowser for help on using the repository browser.