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