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