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