| 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 | pnototal=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 make sure that a directory is made
|
|---|
| 116 | function makedir()
|
|---|
| 117 | {
|
|---|
| 118 | if [ ! -d $@ ]
|
|---|
| 119 | then
|
|---|
| 120 | mkdir -pv $@
|
|---|
| 121 | if [ ! -d $@ ]
|
|---|
| 122 | then
|
|---|
| 123 | echo "could not make dir "$@
|
|---|
| 124 | finish
|
|---|
| 125 | fi
|
|---|
| 126 | fi
|
|---|
| 127 | }
|
|---|
| 128 |
|
|---|
| 129 | # function to check if a process is already locked
|
|---|
| 130 | function checklock()
|
|---|
| 131 | {
|
|---|
| 132 | date > $lockfile
|
|---|
| 133 | checklock0=$?
|
|---|
| 134 | case $checklock0 in
|
|---|
| 135 | 0) echo "checklock0=$checklock0 -> continue " ;;
|
|---|
| 136 | 1) echo "checklock0=$checklock0 -> file $lockfile exists "
|
|---|
| 137 | echo "-> $@ $program is running -> exit"
|
|---|
| 138 | date
|
|---|
| 139 | exit;;
|
|---|
| 140 | *) echo "checklock0=$checklock0 -> something went completely wrong" ;;
|
|---|
| 141 | esac
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | # function calling the macro, which is producing the todo-list
|
|---|
| 145 | function getdolist()
|
|---|
| 146 | {
|
|---|
| 147 | datetime=`date +%F-%H-%M-%S`
|
|---|
| 148 | year=`date +%Y`
|
|---|
| 149 | date=NULL
|
|---|
| 150 |
|
|---|
| 151 | getstatuslogpath=$logpath/getstatus/$program/$year
|
|---|
| 152 | getstatuslog=$getstatuslogpath/getstatus-$table-$column-$datetime.log
|
|---|
| 153 | makedir $getstatuslogpath
|
|---|
| 154 |
|
|---|
| 155 | # get todo list
|
|---|
| 156 | echo "getting todo list..."
|
|---|
| 157 | check0=`root -q -b $macrospath/getdolist.C+\("\"$table\""\,"\"$column\""\,"\"$date\""\,"\"$listpath\""\) | tee $getstatuslog | grep int | sed -e 's/(int)//'`
|
|---|
| 158 |
|
|---|
| 159 | case $check0 in
|
|---|
| 160 | 1) echo "check0=$check0 -> everything ok, got todo list -> run $program";;
|
|---|
| 161 | *) echo "check0=$check0 -> ERROR -> could not get todo list -> exit"
|
|---|
| 162 | finish ;;
|
|---|
| 163 | esac
|
|---|
| 164 |
|
|---|
| 165 | }
|
|---|
| 166 |
|
|---|
| 167 | function resetstatusvalues()
|
|---|
| 168 | {
|
|---|
| 169 | statustime=NULL
|
|---|
| 170 | starttime=NULL
|
|---|
| 171 | returncode=NULL
|
|---|
| 172 | failedcode=NULL
|
|---|
| 173 | failedcodeadd=NULL
|
|---|
| 174 | failedtime=NULL
|
|---|
| 175 | }
|
|---|
| 176 |
|
|---|
| 177 | function printstatusvalues()
|
|---|
| 178 | {
|
|---|
| 179 | echo "the current values are:"
|
|---|
| 180 | echo " statustime=$statustime"
|
|---|
| 181 | echo " starttime=$starttime"
|
|---|
| 182 | echo " returncode=$returncode"
|
|---|
| 183 | echo " failedcode=$failedcode"
|
|---|
| 184 | echo " failedcodeadd=$failedcodeadd"
|
|---|
| 185 | echo " failedtime=$failedtime"
|
|---|
| 186 | echo "-- check: -$check-"
|
|---|
| 187 | echo ""
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | # function calling the macro to set the status, after a process has finished
|
|---|
| 191 | function setstatus()
|
|---|
| 192 | {
|
|---|
| 193 | # set status values
|
|---|
| 194 | resetstatusvalues
|
|---|
| 195 | case $@ in
|
|---|
| 196 | start) echo "start"
|
|---|
| 197 | starttime="Now()"
|
|---|
| 198 | ;;
|
|---|
| 199 | stop) echo "stop"
|
|---|
| 200 | case $check in
|
|---|
| 201 | ok) echo " ok"
|
|---|
| 202 | statustime="Now()"
|
|---|
| 203 | ;;
|
|---|
| 204 | no) echo "nothing new"
|
|---|
| 205 | check="ok"
|
|---|
| 206 | ;;
|
|---|
| 207 | *) echo " failed"
|
|---|
| 208 | starttime=noreset
|
|---|
| 209 | returncode=$check
|
|---|
| 210 | failedcode=$com
|
|---|
| 211 | if ! [ "$comadd" = "" ]
|
|---|
| 212 | then
|
|---|
| 213 | failedcodeadd=$comadd
|
|---|
| 214 | fi
|
|---|
| 215 | failedtime="Now()"
|
|---|
| 216 | check="ok"
|
|---|
| 217 | ;;
|
|---|
| 218 | esac
|
|---|
| 219 | ;;
|
|---|
| 220 | *) echo "error -> exit"
|
|---|
| 221 | exit
|
|---|
| 222 | ;;
|
|---|
| 223 | esac
|
|---|
| 224 |
|
|---|
| 225 | # printstatusvalues
|
|---|
| 226 | # set status
|
|---|
| 227 | setstatuslogpath=$logpath/setstatus/$program/$var1
|
|---|
| 228 | makedir $setstatuslogpath
|
|---|
| 229 | setstatuslog=$setstatuslogpath/setstatus-$@-$program-$var2.log
|
|---|
| 230 | checkstatus=`root -q -b $macrospath/setstatus.C+\("\"$var2\""\,"\"$table\""\,"\"$column\""\,"\"$statustime\""\,"\"$returncode\""\,"\"$failedcode\""\,"\"$failedcodeadd\""\,"\"$starttime\""\,"\"$failedtime\""\) | tee $setstatuslog | grep int | sed -e 's/(int)//'`
|
|---|
| 231 | case $checkstatus in
|
|---|
| 232 | 1) echo "checkstatus=$checkstatus -> everything ok, status has been set";;
|
|---|
| 233 | *) echo "checkstatus=$checkstatus -> ERROR -> step could not be set -> exit"
|
|---|
| 234 | finish ;;
|
|---|
| 235 | esac
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | function getdbsetup()
|
|---|
| 239 | {
|
|---|
| 240 | db=`grep Database $mars/sql.rc | grep -v '#' | sed -e 's/Database: //' -e 's/ //g'`
|
|---|
| 241 | pw=`grep Password $mars/sql.rc | grep -v '#' | sed -e 's/Password: //' -e 's/ //g'`
|
|---|
| 242 | us=`grep User $mars/sql.rc | grep -v '#' | sed -e 's/User: //' -e 's/ //g'`
|
|---|
| 243 | # echo "setup: "
|
|---|
| 244 | # echo " db: "$db
|
|---|
| 245 | # echo " pw: "$pw
|
|---|
| 246 | # echo " us: "$us
|
|---|
| 247 | }
|
|---|
| 248 |
|
|---|
| 249 | function getstepinfo()
|
|---|
| 250 | {
|
|---|
| 251 | if [ "$singleprocess" = "yes" ]
|
|---|
| 252 | then
|
|---|
| 253 | column=${scriptscolname[$i]}
|
|---|
| 254 | fi
|
|---|
| 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 contex()
|
|---|
| 267 | {
|
|---|
| 268 | echo ""
|
|---|
| 269 | if [ "$singleprocess" = "yes" ]
|
|---|
| 270 | then
|
|---|
| 271 | continue
|
|---|
| 272 | else
|
|---|
| 273 | exit
|
|---|
| 274 | fi
|
|---|
| 275 | }
|
|---|
| 276 |
|
|---|
| 277 | function gettodo()
|
|---|
| 278 | {
|
|---|
| 279 | echo "getting todo..."
|
|---|
| 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 | if ! echo $influences | grep '#' > /dev/null
|
|---|
| 292 | then
|
|---|
| 293 | for influence in $influences
|
|---|
| 294 | do
|
|---|
| 295 | query=$query" isnull($influence) and"
|
|---|
| 296 | done
|
|---|
| 297 | fi
|
|---|
| 298 | query=$query" isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) order by $primary desc "
|
|---|
| 299 | if [ "$singleprocess" = "yes" ]
|
|---|
| 300 | then
|
|---|
| 301 | query=$query" limit 0, 1 "
|
|---|
| 302 | fi
|
|---|
| 303 | # echo " QUERY: "$query
|
|---|
| 304 | process=`mysql -s -u $us --password=$pw --host=hercules $db -e " $query "`
|
|---|
| 305 |
|
|---|
| 306 | if [ "$process" = "" ]
|
|---|
| 307 | then
|
|---|
| 308 | echo " => nothing to do"
|
|---|
| 309 | contex
|
|---|
| 310 | else
|
|---|
| 311 | if [ "$singleprocess" = "yes" ]
|
|---|
| 312 | then
|
|---|
| 313 | listfile=$listpath/ToDo-$table-$column-$process.txt
|
|---|
| 314 | echo " => found $process"
|
|---|
| 315 | else
|
|---|
| 316 | listfile=$listpath/ToDo-$table-$column.txt
|
|---|
| 317 | echo "found processes"
|
|---|
| 318 | fi
|
|---|
| 319 | # echo " list: "$listfile
|
|---|
| 320 |
|
|---|
| 321 | if ls $listfile > /dev/null 2>&1
|
|---|
| 322 | then
|
|---|
| 323 | echo "$listfile exists already"
|
|---|
| 324 | contex
|
|---|
| 325 | fi
|
|---|
| 326 | echo $process > $listfile
|
|---|
| 327 | fi
|
|---|
| 328 | }
|
|---|