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