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