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/2005 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2006
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This a resource file for the scripts, in which the standard paths and
|
---|
28 | # functions, which are needed more often are stored.
|
---|
29 | # Only constant variables are stored here, changing variables are stored
|
---|
30 | # in datacenter/scripts/setup
|
---|
31 | #
|
---|
32 |
|
---|
33 | source `dirname $0`/setup
|
---|
34 |
|
---|
35 | mars=`dirname $0 | sed -e 's/\/datacenter\/scripts//'`
|
---|
36 | macrospath=$mars/datacenter/macros
|
---|
37 | scriptspath=$mars/datacenter/scripts
|
---|
38 |
|
---|
39 | webpath=/www/htdocs/datacenter
|
---|
40 |
|
---|
41 | runlogpath=$logpath/run/`date +%Y/%m/%d`
|
---|
42 | processlogpath=$logpath/processlog
|
---|
43 |
|
---|
44 | datetime=`date +%F-%H-%M-%S`
|
---|
45 |
|
---|
46 | check="ok"
|
---|
47 |
|
---|
48 | #failed codes
|
---|
49 | #sequence build status
|
---|
50 | Fbuildsequ=1
|
---|
51 | Fdoexcl=2
|
---|
52 | #run process status
|
---|
53 | Ftimecorr=3
|
---|
54 | Ffillraw=4
|
---|
55 | Fsinope=5
|
---|
56 | Ffillsinope=6
|
---|
57 | Fresetexcl=7
|
---|
58 | #sequence process status
|
---|
59 | Fwritesequfile=8
|
---|
60 | Ffilesavail=9
|
---|
61 | Fnoccfile=10
|
---|
62 | Fnocacofile=11
|
---|
63 | Fmerppcc=12
|
---|
64 | Fmerppcaco=13
|
---|
65 | Fcallisto=14
|
---|
66 | Ffillcalib=15
|
---|
67 | Ffillsignal=16
|
---|
68 | Fstar=17
|
---|
69 | Ffillstar=18
|
---|
70 | #dataset process status
|
---|
71 | Fstardone=19
|
---|
72 | Fganymed=20
|
---|
73 | Ffillganymed=21
|
---|
74 |
|
---|
75 | #
|
---|
76 | # setup for jobmanager
|
---|
77 | #
|
---|
78 | #log files (can't be defined in script itself, as script can run longer
|
---|
79 | #than one day
|
---|
80 | jmerrorlog=$runlogpath/jobmanager-error`date +%F`.log
|
---|
81 | jmscriptlog=$runlogpath/jobmanager`date +%F`.log
|
---|
82 | steps=$mars/steps.rc
|
---|
83 | # resetting values
|
---|
84 | pno=0
|
---|
85 | totalpno=0
|
---|
86 | running=0
|
---|
87 | queued=0
|
---|
88 | runningscript=0
|
---|
89 | queuedscript=0
|
---|
90 | stillinqueue=0
|
---|
91 |
|
---|
92 | function setzero()
|
---|
93 | {
|
---|
94 | val=$@
|
---|
95 | if [ "$val" == "" ]
|
---|
96 | then
|
---|
97 | test=`condor_q -global`
|
---|
98 | if [ "$test" == "" ]
|
---|
99 | then
|
---|
100 | echo $max
|
---|
101 | else
|
---|
102 | echo 0
|
---|
103 | fi
|
---|
104 | else
|
---|
105 | echo $val
|
---|
106 | fi
|
---|
107 | }
|
---|
108 |
|
---|
109 |
|
---|
110 |
|
---|
111 | # in the following the function, which are needed by several scripts, are
|
---|
112 | # defined
|
---|
113 |
|
---|
114 | # function to make sure that a directory is made
|
---|
115 | function makedir()
|
---|
116 | {
|
---|
117 | if [ ! -d $@ ]
|
---|
118 | then
|
---|
119 | mkdir -pv $@
|
---|
120 | if [ ! -d $@ ]
|
---|
121 | then
|
---|
122 | echo "could not make dir "$@
|
---|
123 | finish
|
---|
124 | fi
|
---|
125 | fi
|
---|
126 | }
|
---|
127 | makedir $runlogpath
|
---|
128 | makedir $processlogpath
|
---|
129 | processlog=$processlogpath/process`date +%F`.log
|
---|
130 |
|
---|
131 | function printprocesslog
|
---|
132 | {
|
---|
133 | makedir $processlogpath
|
---|
134 | echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] "$@ >> $processlog
|
---|
135 | }
|
---|
136 |
|
---|
137 | # function to exit a script properly
|
---|
138 | function finish()
|
---|
139 | {
|
---|
140 | rm -v $todofile
|
---|
141 | rm -v $lockfile
|
---|
142 | date
|
---|
143 | printprocesslog "INFO finished $program"
|
---|
144 | exit
|
---|
145 | }
|
---|
146 |
|
---|
147 | # function to do continue in a loop and produce according logging
|
---|
148 | function cont()
|
---|
149 | {
|
---|
150 | date
|
---|
151 | echo ""
|
---|
152 | continue
|
---|
153 | }
|
---|
154 |
|
---|
155 | # function to check if a process is already locked
|
---|
156 | function checklock()
|
---|
157 | {
|
---|
158 | date > $lockfile
|
---|
159 | checklock0=$?
|
---|
160 | case $checklock0 in
|
---|
161 | 0) echo " checklock0=$checklock0 -> continue " ;;
|
---|
162 | 1) echo " checklock0=$checklock0 -> file $lockfile exists -> exit"
|
---|
163 | date
|
---|
164 | exit;;
|
---|
165 | *) echo " checklock0=$checklock0 -> something went completely wrong" ;;
|
---|
166 | esac
|
---|
167 | }
|
---|
168 |
|
---|
169 | # function calling the macro, which is producing the todo-list
|
---|
170 | function getdolistroot()
|
---|
171 | {
|
---|
172 | datetime=`date +%F-%H-%M-%S`
|
---|
173 | year=`date +%Y`
|
---|
174 | date=NULL
|
---|
175 |
|
---|
176 | getstatuslogpath=$logpath/getstatus/$program/$year
|
---|
177 | getstatuslog=$getstatuslogpath/getstatus-$table-$column-$datetime.log
|
---|
178 | makedir $getstatuslogpath
|
---|
179 |
|
---|
180 | # get todo list
|
---|
181 | echo "getting todo list..."
|
---|
182 | check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\,"\"$listpath\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
|
---|
183 |
|
---|
184 | case $check0 in
|
---|
185 | 1) echo " check0=$check0 -> everything ok, got todo list -> run $program";;
|
---|
186 | *) echo " check0=$check0 -> ERROR -> could not get todo list -> exit"
|
---|
187 | finish ;;
|
---|
188 | esac
|
---|
189 |
|
---|
190 | }
|
---|
191 |
|
---|
192 | function resetstatusvalues()
|
---|
193 | {
|
---|
194 | statustime=NULL
|
---|
195 | starttime=NULL
|
---|
196 | returncode=NULL
|
---|
197 | failedcode=NULL
|
---|
198 | failedcodeadd=NULL
|
---|
199 | failedtime=NULL
|
---|
200 | }
|
---|
201 |
|
---|
202 | function printstatusvalues()
|
---|
203 | {
|
---|
204 | echo "the current values are:"
|
---|
205 | echo " statustime=$statustime"
|
---|
206 | echo " starttime=$starttime"
|
---|
207 | echo " returncode=$returncode"
|
---|
208 | echo " failedcode=$failedcode"
|
---|
209 | echo " failedcodeadd=$failedcodeadd"
|
---|
210 | echo " failedtime=$failedtime"
|
---|
211 | echo "-- check: -$check-"
|
---|
212 | echo ""
|
---|
213 | }
|
---|
214 |
|
---|
215 | # function evaluating the statusvalues
|
---|
216 | function evalstatus()
|
---|
217 | {
|
---|
218 | case $@ in
|
---|
219 | start) echo "setstatus start"
|
---|
220 | starttime="Now()"
|
---|
221 | ;;
|
---|
222 | stop) echo "setstatus stop"
|
---|
223 | case $check in
|
---|
224 | ok) echo " ok"
|
---|
225 | statustime="Now()"
|
---|
226 | ;;
|
---|
227 | no) echo "nothing new"
|
---|
228 | check="ok"
|
---|
229 | ;;
|
---|
230 | *) echo " failed"
|
---|
231 | starttime=noreset
|
---|
232 | returncode=$check
|
---|
233 | failedcode=$com
|
---|
234 | if ! [ "$comadd" = "" ]
|
---|
235 | then
|
---|
236 | failedcodeadd=$comadd
|
---|
237 | fi
|
---|
238 | failedtime="Now()"
|
---|
239 | check="ok"
|
---|
240 | ;;
|
---|
241 | esac
|
---|
242 | ;;
|
---|
243 | *) echo "error -> exit"
|
---|
244 | printprocesslog "ERROR function evalstatus got wrong variable"
|
---|
245 | finish
|
---|
246 | ;;
|
---|
247 | esac
|
---|
248 | }
|
---|
249 |
|
---|
250 | # function calling the macro to set the status, after a process has finished
|
---|
251 | function setstatusroot()
|
---|
252 | {
|
---|
253 | # set status values
|
---|
254 | resetstatusvalues
|
---|
255 | evalstatus $@
|
---|
256 |
|
---|
257 | # printstatusvalues
|
---|
258 | # set status
|
---|
259 | setstatuslogpath=$logpath/setstatus/$program/$var1
|
---|
260 | makedir $setstatuslogpath
|
---|
261 | setstatuslog=$setstatuslogpath/setstatus-$@-$program-$var2.log
|
---|
262 | checkstatus=`root -q -b $macrospath/setstatus.C+\("\"$var2\""\,"\"$table\""\,"\"$column\""\,"\"$statustime\""\,"\"$returncode\""\,"\"$failedcode\""\,"\"$failedcodeadd\""\,"\"$starttime\""\,"\"$failedtime\""\) | tee $setstatuslog | grep int | sed -e 's/(int)//'`
|
---|
263 | case $checkstatus in
|
---|
264 | 1) echo " checkstatus=$checkstatus -> everything ok, status has been set";;
|
---|
265 | *) echo " checkstatus=$checkstatus -> ERROR -> step could not be set -> exit"
|
---|
266 | finish ;;
|
---|
267 | esac
|
---|
268 | }
|
---|
269 |
|
---|
270 | function getdbsetup()
|
---|
271 | {
|
---|
272 | db=`grep Database $mars/sql.rc | grep -v '#' | sed -e 's/Database: //' -e 's/ //g'`
|
---|
273 | pw=`grep Password $mars/sql.rc | grep -v '#' | sed -e 's/Password: //' -e 's/ //g'`
|
---|
274 | us=`grep User $mars/sql.rc | grep -v '#' | sed -e 's/User: //' -e 's/ //g'`
|
---|
275 | # echo "setup: "
|
---|
276 | # echo " db: "$db
|
---|
277 | # echo " pw: "$pw
|
---|
278 | # echo " us: "$us
|
---|
279 | }
|
---|
280 |
|
---|
281 | function getstepinfo()
|
---|
282 | {
|
---|
283 | table=`grep "$column:" $steps | sed -e "s/[.]$column://" -e 's/#//' -e 's/ //g'`
|
---|
284 | coltab=`grep "$column:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'`
|
---|
285 | needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"`
|
---|
286 | influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"`
|
---|
287 | primary=`grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"`
|
---|
288 | # echo " column $column - table $table - coltab $coltab"
|
---|
289 | # echo " needs: $needs"
|
---|
290 | # echo " influences: $influences"
|
---|
291 | # echo " primary: $primary"
|
---|
292 | }
|
---|
293 |
|
---|
294 | # function to get todolist
|
---|
295 | function getdolist()
|
---|
296 | {
|
---|
297 | echo "getting todolist..."
|
---|
298 | getdbsetup
|
---|
299 | getstepinfo
|
---|
300 | # get query
|
---|
301 | query=" select $primary from $table where "
|
---|
302 | if ! echo $needs | grep '#' > /dev/null
|
---|
303 | then
|
---|
304 | for need in $needs
|
---|
305 | do
|
---|
306 | query=$query" not isnull($need) and"
|
---|
307 | done
|
---|
308 | fi
|
---|
309 | query=$query" isnull($column) "
|
---|
310 | query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
|
---|
311 | query=$query" order by $primary desc "
|
---|
312 | # echo " QUERY: "$query
|
---|
313 | if ! process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
|
---|
314 | then
|
---|
315 | echo "ERROR could not query processes from db -> exit"
|
---|
316 | printprocesslog "ERROR could not query processes from db (program: $program, function getdolist)"
|
---|
317 | finish
|
---|
318 | fi
|
---|
319 |
|
---|
320 | if [ "$process" = "" ]
|
---|
321 | then
|
---|
322 | echo " => nothing to do"
|
---|
323 | finish
|
---|
324 | else
|
---|
325 | todofile=$listpath/ToDo-$table-$column.txt
|
---|
326 |
|
---|
327 | if ls $todofile > /dev/null 2>&1
|
---|
328 | then
|
---|
329 | echo "$todofile exists already"
|
---|
330 | printprocesslog "WARN $todofile exists already (program: $program, function getdolist)"
|
---|
331 | finish
|
---|
332 | fi
|
---|
333 | echo "found processes, writing todofile..."
|
---|
334 | echo $process > $todofile
|
---|
335 | fi
|
---|
336 | }
|
---|
337 |
|
---|
338 | # function to get todo (process)
|
---|
339 | function gettodo()
|
---|
340 | {
|
---|
341 | process=
|
---|
342 | echo "getting todo..."
|
---|
343 | getdbsetup
|
---|
344 | getstepinfo
|
---|
345 | # get query
|
---|
346 | query=" select $primary from $table where "
|
---|
347 | if ! echo $needs | grep '#' > /dev/null
|
---|
348 | then
|
---|
349 | for need in $needs
|
---|
350 | do
|
---|
351 | query=$query" not isnull($need) and"
|
---|
352 | done
|
---|
353 | fi
|
---|
354 | query=$query" isnull($column) "
|
---|
355 | query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
|
---|
356 | query=$query" order by $primary desc "
|
---|
357 | query=$query" limit 0, 1 "
|
---|
358 | # echo " QUERY: "$query
|
---|
359 | if ! process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
|
---|
360 | then
|
---|
361 | echo "ERROR could not query process from db -> exit"
|
---|
362 | printprocesslog "ERROR could not query process from db (program: $program, function gettodo)"
|
---|
363 | finish
|
---|
364 | fi
|
---|
365 |
|
---|
366 | if [ "$process" = "" ]
|
---|
367 | then
|
---|
368 | echo " => nothing to do -> exit"
|
---|
369 | finish
|
---|
370 | fi
|
---|
371 | }
|
---|
372 |
|
---|
373 | # function to get the number of processes which still have to be done
|
---|
374 | function getstatus()
|
---|
375 | {
|
---|
376 | numproc=
|
---|
377 | # echo "getting status..."
|
---|
378 | getdbsetup
|
---|
379 | column=${scriptscolname[$i]}
|
---|
380 | getstepinfo
|
---|
381 | # get query
|
---|
382 | query=" select count(*) from $table where "
|
---|
383 | if ! echo $needs | grep '#' > /dev/null
|
---|
384 | then
|
---|
385 | for need in $needs
|
---|
386 | do
|
---|
387 | query=$query" not isnull($need) and"
|
---|
388 | done
|
---|
389 | fi
|
---|
390 | query=$query" isnull($column) "
|
---|
391 | query=$query" and isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) "
|
---|
392 | query=$query" group by $column "
|
---|
393 | # echo " QUERY: "$query
|
---|
394 | if ! numproc=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
|
---|
395 | then
|
---|
396 | echo "ERROR could not query number of todo proceses from db -> continue"
|
---|
397 | printprocesslog "ERROR could not query number of processes from db (program: $program, function getstatus)"
|
---|
398 | cont
|
---|
399 | fi
|
---|
400 | }
|
---|
401 |
|
---|
402 | # function to set status of a process in the db
|
---|
403 | function setstatus()
|
---|
404 | {
|
---|
405 | resetstatusvalues
|
---|
406 | evalstatus $@
|
---|
407 | getdbsetup
|
---|
408 | getstepinfo
|
---|
409 | # get query
|
---|
410 | reset=`grep "$coltab[.]Reset:" $steps | sed -e "s/$coltab[.]Reset://" -e 's/ //g'`
|
---|
411 | if [ "$reset" = "no" ]
|
---|
412 | then
|
---|
413 | echo "YOU CAN'T RESET $column for $var2!!!"
|
---|
414 | printprocesslog "ERROR you can't reset $column for $var2"
|
---|
415 | finish
|
---|
416 | fi
|
---|
417 | query=" update $table set $column=$statustime"
|
---|
418 | if ! echo $influences | grep '#' > /dev/null
|
---|
419 | then
|
---|
420 | for influence in $influences
|
---|
421 | do
|
---|
422 | query=$query", $influence=NULL"
|
---|
423 | done
|
---|
424 | fi
|
---|
425 | if ! [ "$starttime" = "noreset" ]
|
---|
426 | then
|
---|
427 | query=$query", fStartTime=$starttime"
|
---|
428 | fi
|
---|
429 | query=$query", fFailedTime=$failedtime, fFailedCode=$failedcode, fFailedCodeAdd=$failedcodeadd, fReturnCode=$returncode "
|
---|
430 | query=$query" where $primary=$var2"
|
---|
431 | echo " QUERY: "$query
|
---|
432 | if ! mysql -s -u $us --password=$pw --host=hercules $db -e " $query "
|
---|
433 | then
|
---|
434 | echo "ERROR could not insert status into db -> exit"
|
---|
435 | printprocesslog "ERROR could not set status in db (program: $program, function setstatus)"
|
---|
436 | finish
|
---|
437 | fi
|
---|
438 |
|
---|
439 | }
|
---|