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