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-2007
|
---|
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 | # check if script has been started with absolute path
|
---|
34 | if ! dirname $0 | grep -E '^/' >/dev/null 2>&1
|
---|
35 | then
|
---|
36 | echo "Please start your script with an absolute path."
|
---|
37 | exit
|
---|
38 | fi
|
---|
39 |
|
---|
40 | if [ "$AUTOMATIONSETUP" = "" ]
|
---|
41 | then
|
---|
42 | echo "Please set the environment variable \$AUTOMATIONSETUP."
|
---|
43 | exit
|
---|
44 | fi
|
---|
45 |
|
---|
46 | source `dirname $0`/setup.$AUTOMATIONSETUP
|
---|
47 |
|
---|
48 | datetime=`date +%F-%H-%M-%S`
|
---|
49 |
|
---|
50 |
|
---|
51 | # function to make sure that a directory is made
|
---|
52 | function makedir()
|
---|
53 | {
|
---|
54 | if [ ! -d $@ ]
|
---|
55 | then
|
---|
56 | mkdir -pv $@
|
---|
57 | if [ ! -d $@ ]
|
---|
58 | then
|
---|
59 | echo "could not make dir "$@
|
---|
60 | if ! [ "$processlog" = "" ]
|
---|
61 | then
|
---|
62 | echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] could not make dir "$@ >> $processlog
|
---|
63 | fi
|
---|
64 | if ls $lockfile >/dev/null 2>&1
|
---|
65 | then
|
---|
66 | rm -v $lockfile
|
---|
67 | fi
|
---|
68 | exit
|
---|
69 | fi
|
---|
70 | fi
|
---|
71 | }
|
---|
72 |
|
---|
73 | # logging paths for runlogs and processlog
|
---|
74 | runlogpath=$logpath/run/`date +%Y/%m/%d`
|
---|
75 | processlogpath=$logpath/processlog
|
---|
76 | makedir $runlogpath
|
---|
77 | makedir $processlogpath
|
---|
78 | processlog=$processlogpath/process`date +%F`.log
|
---|
79 |
|
---|
80 | makedir $lockpath
|
---|
81 |
|
---|
82 |
|
---|
83 | # function to provide proper logging in a single logfile ($processlog)
|
---|
84 | function printprocesslog
|
---|
85 | {
|
---|
86 | makedir $processlogpath
|
---|
87 | echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] "$@ >> $processlog
|
---|
88 | }
|
---|
89 |
|
---|
90 | # function to exit a script properly
|
---|
91 | function finish()
|
---|
92 | {
|
---|
93 | if ! [ "$lockfile" = "" ] && ls $lockfile >/dev/null 2>&1
|
---|
94 | then
|
---|
95 | printprocesslog "INFO " `rm -v $lockfile`
|
---|
96 | fi
|
---|
97 | printprocesslog "INFO finished $0"
|
---|
98 | exit
|
---|
99 | }
|
---|
100 |
|
---|
101 |
|
---|
102 | # set checkvalue to ok at the beginning of the scripts
|
---|
103 | check="ok"
|
---|
104 |
|
---|
105 | #failed codes
|
---|
106 | #sequence build status
|
---|
107 | Fbuildsequ=1
|
---|
108 | Fdoexcl=2
|
---|
109 | #run process status
|
---|
110 | Ftimecorr=3
|
---|
111 | Ffillraw=4
|
---|
112 | Fsinope=5
|
---|
113 | Ffillsinope=6
|
---|
114 | Fresetexcl=7
|
---|
115 | #sequence process status
|
---|
116 | Fwritesequfile=8
|
---|
117 | Ffilesavail=9
|
---|
118 | Fnoccfile=10
|
---|
119 | Fnocacofile=11
|
---|
120 | Fmerppcc=12
|
---|
121 | Fmerppcaco=13
|
---|
122 | Fcallisto=14
|
---|
123 | Ffillcalib=15
|
---|
124 | Ffillsignal=16
|
---|
125 | Fstar=17
|
---|
126 | Ffillstar=18
|
---|
127 | #dataset process status
|
---|
128 | Fwritedatasetfile=19
|
---|
129 | Fstardone=20
|
---|
130 | Fganymed=21
|
---|
131 | Ffillganymed=22
|
---|
132 | #again run process status
|
---|
133 | FCompmux=26
|
---|
134 | Fdowebplots=27
|
---|
135 | #again mc run process status
|
---|
136 | Fmccallisto=28
|
---|
137 | Ffillmccalib=29
|
---|
138 | Ffillmcsignal=30
|
---|
139 | Fmcstar=31
|
---|
140 | Ffillmcstar=32
|
---|
141 | Fcorsikasimtel=33
|
---|
142 | Fchimp=34
|
---|
143 | Fchimpcp=35
|
---|
144 | Fctastar=36
|
---|
145 | Fctastarcp=37
|
---|
146 | FctastereoA=38
|
---|
147 | FctastereoB=39
|
---|
148 | FctastereoC=40
|
---|
149 | FctastereoD=41
|
---|
150 | FctastereoE=42
|
---|
151 | FctastereoF=43
|
---|
152 | FctastereoG=44
|
---|
153 | FctastereoH=45
|
---|
154 | Fctastereocp=46
|
---|
155 |
|
---|
156 | # setup for jobmanager:
|
---|
157 | # log files (can't be defined in script itself, as script can run longer
|
---|
158 | # than one day
|
---|
159 | jmerrorlog=$runlogpath/jobmanager-error`date +%F`.log
|
---|
160 | jmscriptlog=$runlogpath/jobmanager`date +%F`.log
|
---|
161 |
|
---|
162 | # check if rc-files are available
|
---|
163 | if ! ls $steps >/dev/null
|
---|
164 | then
|
---|
165 | echo "Can't find steps.rc ($steps)"
|
---|
166 | finish
|
---|
167 | fi
|
---|
168 | if ! ls $sqlrc >/dev/null
|
---|
169 | then
|
---|
170 | echo "Can't find sql.rc ($sqlrc)"
|
---|
171 | finish
|
---|
172 | fi
|
---|
173 |
|
---|
174 | # resetting values
|
---|
175 | pno=0
|
---|
176 | totalpno=0
|
---|
177 | running=0
|
---|
178 | queued=0
|
---|
179 | runningscript=0
|
---|
180 | queuedscript=0
|
---|
181 | stillinqueue=0
|
---|
182 |
|
---|
183 |
|
---|
184 | # alias (we cannot check the beginning of the line due to
|
---|
185 | # color codes in filldotraw.C)
|
---|
186 | alias 'intgrep'='grep -E -o \\\(int\\\)[0-9]+$ | grep -E -o [0-9]+'
|
---|
187 |
|
---|
188 |
|
---|
189 | # in the following the functions, which are needed by several scripts, are
|
---|
190 | # defined
|
---|
191 |
|
---|
192 | # function to check if a process is already locked
|
---|
193 | # command line option can be used to execute something, e.g. 'continue'
|
---|
194 | function checklock()
|
---|
195 | {
|
---|
196 | if ! echo `date +%F\ %T`" "`whoami`"@"$HOSTNAME" "`basename $0`"["$$"] "`uname -a` > $lockfile 2>/dev/null
|
---|
197 | then
|
---|
198 | printprocesslog "WARN lockfile $lockfile exists"
|
---|
199 | $@
|
---|
200 | exit
|
---|
201 | else
|
---|
202 | printprocesslog "INFO created lockfile $lockfile"
|
---|
203 | fi
|
---|
204 | }
|
---|
205 |
|
---|
206 | function resetstatusvalues()
|
---|
207 | {
|
---|
208 | statustime=NULL
|
---|
209 | starttime=NULL
|
---|
210 | returncode=NULL
|
---|
211 | programid=NULL
|
---|
212 | failedtime=NULL
|
---|
213 | }
|
---|
214 |
|
---|
215 | function printstatusvalues()
|
---|
216 | {
|
---|
217 | echo "the current values are:"
|
---|
218 | echo " statustime=$statustime"
|
---|
219 | echo " starttime=$starttime"
|
---|
220 | echo " returncode=$returncode"
|
---|
221 | echo " programid=$programid"
|
---|
222 | echo " failedtime=$failedtime"
|
---|
223 | echo "-- check: -$check-"
|
---|
224 | echo ""
|
---|
225 | }
|
---|
226 |
|
---|
227 | # function evaluating the statusvalues
|
---|
228 | function evalstatus()
|
---|
229 | {
|
---|
230 | case $@ in
|
---|
231 | start) printprocesslog "INFO setstatus start"
|
---|
232 | starttime="Now()"
|
---|
233 | ;;
|
---|
234 | stop) case $check in
|
---|
235 | ok) printprocesslog "INFO setstatus stop - ok"
|
---|
236 | statustime="Now()"
|
---|
237 | ;;
|
---|
238 | no) printprocesslog "INFO setstatus stop - nothing new"
|
---|
239 | check="ok"
|
---|
240 | ;;
|
---|
241 | *) printprocesslog "INFO setstatus stop - failed"
|
---|
242 | starttime=noreset
|
---|
243 | if [ "$check" == "" ]
|
---|
244 | then
|
---|
245 | returncode=1
|
---|
246 | else
|
---|
247 | returncode=$check
|
---|
248 | fi
|
---|
249 | programid=$com
|
---|
250 | failedtime="Now()"
|
---|
251 | check="ok"
|
---|
252 | ;;
|
---|
253 | esac
|
---|
254 | ;;
|
---|
255 | *) printprocesslog "ERROR function evalstatus got wrong variable"
|
---|
256 | finish
|
---|
257 | ;;
|
---|
258 | esac
|
---|
259 | }
|
---|
260 |
|
---|
261 | function getdbsetup()
|
---|
262 | {
|
---|
263 | db=`grep Database $sqlrc | grep -v '#' | sed -e 's/Database: //' -e 's/ //g'`
|
---|
264 | pw=`grep Password $sqlrc | grep -v '#' | sed -e 's/Password: //' -e 's/ //g'`
|
---|
265 | us=`grep User $sqlrc | grep -v '#' | sed -e 's/User: //' -e 's/ //g'`
|
---|
266 | ho=`grep URL $sqlrc | grep -v '#' | sed -e 's/ //g' -e 's/URL:mysql:\/\///'`
|
---|
267 | # echo "setup: "
|
---|
268 | # echo " db: "$db
|
---|
269 | # echo " pw: "$pw
|
---|
270 | # echo " us: "$us
|
---|
271 | # echo " ho: "$ho
|
---|
272 | }
|
---|
273 |
|
---|
274 | function getstepinfo()
|
---|
275 | {
|
---|
276 | getdbsetup
|
---|
277 | table=`grep "$column:" $steps | sed -e "s/[.]$column://" -e 's/#//' -e 's/ //g'`
|
---|
278 | coltab=`grep "$column:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'`
|
---|
279 | needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"`
|
---|
280 | noderestricted=`grep "$coltab[.]NodeRestricted:" $steps | sed -e "s/$coltab[.]NodeRestricted://" -e 's/ //g'`
|
---|
281 | influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"`
|
---|
282 | prims=( `grep "$table[.]Primary:" $steps | sed -e "s/$table[.]Primary://"` )
|
---|
283 | # echo " column $column - table $table - coltab $coltab"
|
---|
284 | # echo " needs: $needs"
|
---|
285 | # echo " influences: $influences"
|
---|
286 | # echo " noderestricted: $noderestricted"
|
---|
287 | # echo " prims: ${prims[@]}"
|
---|
288 | }
|
---|
289 |
|
---|
290 | # function to get todolist
|
---|
291 | function gettodo()
|
---|
292 | {
|
---|
293 | process=
|
---|
294 | printprocesslog "INFO getting todo..."
|
---|
295 | getstepinfo
|
---|
296 | # get query
|
---|
297 | query=" SELECT "${prims[0]}
|
---|
298 | for (( i=1 ; i < ${#prims[@]} ; i++ ))
|
---|
299 | do
|
---|
300 | query=$query", ${prims[$i]}"
|
---|
301 | done
|
---|
302 | query=$query" FROM $table WHERE "
|
---|
303 | if ! echo $needs | grep '#' > /dev/null
|
---|
304 | then
|
---|
305 | for need in $needs
|
---|
306 | do
|
---|
307 | query=$query" NOT ISNULL($need) AND"
|
---|
308 | done
|
---|
309 | fi
|
---|
310 | query=$query" ISNULL($column) "
|
---|
311 | if [ "$2 " != " " ]
|
---|
312 | then
|
---|
313 | query=$query" AND fProductionHostKEY=$2 "
|
---|
314 | fi
|
---|
315 | query=$query" AND ISNULL(fStartTime) AND ISNULL(fFailedTime) AND ISNULL(fProgramId) AND ISNULL(fReturnCode) "
|
---|
316 | query=$query" ORDER BY fPriority desc "
|
---|
317 | if [ "$1 " != " " ]
|
---|
318 | then
|
---|
319 | query=$query" limit 0, $1 "
|
---|
320 | fi
|
---|
321 | # echo " QUERY: "$query
|
---|
322 | printprocesslog "INFO gettodo QUERY: "$query
|
---|
323 | if ! process=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "`
|
---|
324 | then
|
---|
325 | printprocesslog "ERROR could not query processes from db (program: $program, function gettodo)"
|
---|
326 | finish
|
---|
327 | fi
|
---|
328 |
|
---|
329 | if [ "$process" = "" ]
|
---|
330 | then
|
---|
331 | printprocesslog "INFO => nothing to do"
|
---|
332 | finish
|
---|
333 | else
|
---|
334 | primaries=( $process )
|
---|
335 | num=`expr ${#primaries[@]} / ${#prims[@]} `
|
---|
336 | fi
|
---|
337 | }
|
---|
338 |
|
---|
339 |
|
---|
340 | # function to get the number of processes which still have to be done
|
---|
341 | function getstatus()
|
---|
342 | {
|
---|
343 | numproc=
|
---|
344 | getstepinfo
|
---|
345 | # get query
|
---|
346 | query=" SELECT COUNT(*) 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 | if [ "$1 " != " " ]
|
---|
356 | then
|
---|
357 | query=$query" AND fProductionHostKEY=$1 "
|
---|
358 | fi
|
---|
359 | query=$query" AND ISNULL(fStartTime) AND ISNULL(fFailedTime) AND ISNULL(fProgramId) AND ISNULL(fReturnCode) "
|
---|
360 | query=$query" GROUP BY $column "
|
---|
361 | # echo "QUERY: "$query
|
---|
362 | printprocesslog "INFO getstatus QUERY: "$query
|
---|
363 | if ! numproc=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "`
|
---|
364 | then
|
---|
365 | printprocesslog "ERROR could not query number of processes from db (program: $program, function getstatus)"
|
---|
366 | echo `date +%F\ %T`" ERROR could not query number of processes from db (program: $program, function getstatus)"
|
---|
367 | continue
|
---|
368 | fi
|
---|
369 | if [ "$numproc" = "" ]
|
---|
370 | then
|
---|
371 | numproc=0
|
---|
372 | fi
|
---|
373 | }
|
---|
374 |
|
---|
375 | # function to set status of a process in the db
|
---|
376 | function setstatus()
|
---|
377 | {
|
---|
378 | if [ "$column" = "no" ]
|
---|
379 | then
|
---|
380 | return
|
---|
381 | fi
|
---|
382 | resetstatusvalues
|
---|
383 | evalstatus $@
|
---|
384 | getstepinfo
|
---|
385 | # get query
|
---|
386 | reset=`grep "$coltab[.]Reset:" $steps | sed -e "s/$coltab[.]Reset://" -e 's/ //g'`
|
---|
387 | if [ "$reset" = "no" ]
|
---|
388 | then
|
---|
389 | printprocesslog "ERROR You cannot reset $column for ${primaries[$s+$s]}"
|
---|
390 | finish
|
---|
391 | fi
|
---|
392 | query=" update $table set $column=$statustime"
|
---|
393 | if ! echo $influences | grep '#' > /dev/null
|
---|
394 | then
|
---|
395 | for influence in $influences
|
---|
396 | do
|
---|
397 | query=$query", $influence=NULL"
|
---|
398 | done
|
---|
399 | fi
|
---|
400 | if ! [ "$starttime" = "noreset" ]
|
---|
401 | then
|
---|
402 | query=$query", fStartTime=$starttime"
|
---|
403 | fi
|
---|
404 | query=$query", fFailedTime=$failedtime, fProgramId=$programid, fReturnCode=$returncode "
|
---|
405 | query=$query" where "
|
---|
406 | if [ "$s" = "" ]
|
---|
407 | then
|
---|
408 | s=0
|
---|
409 | fi
|
---|
410 | query=$query" ${prims[0]}='${primaries[$s*${#prims[@]}]}'"
|
---|
411 | for (( i=1 ; i < ${#prims[@]} ; i++ ))
|
---|
412 | do
|
---|
413 | query=$query" AND ${prims[$i]}='${primaries[$s*${#prims[@]}+$i]}' "
|
---|
414 | done
|
---|
415 | # echo " QUERY: "$query
|
---|
416 | printprocesslog "INFO setstatus QUERY: "$query
|
---|
417 | if ! mysql -s -u $us --password=$pw --host=$ho $db -e " $query "
|
---|
418 | then
|
---|
419 | printprocesslog "ERROR could not set status in db (program: $program, function setstatus)"
|
---|
420 | finish
|
---|
421 | fi
|
---|
422 |
|
---|
423 | }
|
---|
424 |
|
---|
425 | # function to send a mysql query
|
---|
426 | function sendquery()
|
---|
427 | {
|
---|
428 | getdbsetup
|
---|
429 | printprocesslog "INFO sendquery QUERY: "$query
|
---|
430 | if ! val=`mysql -s -u $us --password=$pw --host=$ho $db -e " $query "`
|
---|
431 | then
|
---|
432 | printprocesslog "ERROR could not query db (program: $program, function sendquery)"
|
---|
433 | return 1
|
---|
434 | fi
|
---|
435 | if [ "$val" = "NULL" ]
|
---|
436 | then
|
---|
437 | val=
|
---|
438 | fi
|
---|
439 | echo $val
|
---|
440 | return 0
|
---|
441 | }
|
---|
442 |
|
---|