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