| 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 paths, times and number
|
|---|
| 28 | # of jobs for condor are stored.
|
|---|
| 29 | #
|
|---|
| 30 |
|
|---|
| 31 |
|
|---|
| 32 | #source `dirname $0`/sourcefile (is done in jobsourcefile)
|
|---|
| 33 |
|
|---|
| 34 | user=`whoami`
|
|---|
| 35 | sourcefile=/home/$user/Mars.cvs/datacenter/scripts/jobsourcefile
|
|---|
| 36 | source $sourcefile
|
|---|
| 37 |
|
|---|
| 38 | notcount=0
|
|---|
| 39 | while (( $notcount < 100 ))
|
|---|
| 40 | do
|
|---|
| 41 | for (( i=0 ; i < ${#scripts[@]} ; i++ ))
|
|---|
| 42 | do
|
|---|
| 43 | date #>> $scriptlog 2>&1
|
|---|
| 44 | echo "sleeping $sleeptime..." #>> $scriptlog 2>&1
|
|---|
| 45 | sleep $sleeptime
|
|---|
| 46 | dayofweek=`date +%u`
|
|---|
| 47 | hour=`date +%k`
|
|---|
| 48 | source $sourcefile
|
|---|
| 49 | echo "script: ${scripts[$i]}" #>> $scriptlog 2>&1
|
|---|
| 50 | echo " day: $dayofweek hour: $hour" #>> $scriptlog 2>&1
|
|---|
| 51 | queued=`/usr/local/bin/condor_q -global -format "%s\n" Owner | grep -c $user`
|
|---|
| 52 | queued=`setzero $queued`
|
|---|
| 53 | echo " found $queued jobs in the queue (incl. running jobs)" #>> $scriptlog 2>&1
|
|---|
| 54 | queuedscript=`/usr/local/bin/condor_q -global | grep $user | grep -c ${scripts[$i]}`
|
|---|
| 55 | queuedscript=`setzero $queuedscript`
|
|---|
| 56 | echo " found $queuedscript ${scripts[$i]} in the queue (incl. running jobs)" #>> $scriptlog 2>&1
|
|---|
| 57 |
|
|---|
| 58 | pnototal=${pnototal[$hour]}
|
|---|
| 59 | #choose array according to the day of the week
|
|---|
| 60 | case $dayofweek in
|
|---|
| 61 | 0 | 6) pnos=( ${pnoswe[@]} ) ;;
|
|---|
| 62 | *) pnos=( ${pnosweek[@]} ) ;;
|
|---|
| 63 | esac
|
|---|
| 64 | num=`echo "((( $i + 1 ) * 24 ) + ( $hour + 1 ) ) - 24 - 1 " | bc `
|
|---|
| 65 | pnoscript=${pnos[$num]}
|
|---|
| 66 | echo " => num=$num => pnoscript=$pnoscript (i.e. $pnoscript ${scripts[$i]} allowed)" #>> $scriptlog 2>&1
|
|---|
| 67 |
|
|---|
| 68 | echo " queued: $queued - pnototal: $pnototal" #>> $scriptlog 2>&1
|
|---|
| 69 | if [ "$queued" -gt "$pnototal" ]
|
|---|
| 70 | then
|
|---|
| 71 | continue
|
|---|
| 72 | else
|
|---|
| 73 | echo " queued ${scripts[$i]}: $queuedscript - pno: $pnoscript" #>> $scriptlog 2>&1
|
|---|
| 74 | if [ "$queuedscript" -gt "$pnoscript" ]
|
|---|
| 75 | then
|
|---|
| 76 | continue
|
|---|
| 77 | fi
|
|---|
| 78 | fi
|
|---|
| 79 |
|
|---|
| 80 | echo " gettodo..."
|
|---|
| 81 | echo "getting db..."
|
|---|
| 82 | db=`grep Database $mars/sql.rc | grep -v '#' | sed -e 's/Database: //' -e 's/ //g'`
|
|---|
| 83 | col=${scriptscolname[$i]}
|
|---|
| 84 | table=`grep "$col:" $steps | sed -e "s/[.]$col://" -e 's/#//' -e 's/ //g'`
|
|---|
| 85 | coltab=`grep "$col:" $steps | sed -e 's/://' -e 's/#//' -e 's/ //g'`
|
|---|
| 86 | needs=`grep "$coltab[.]Needs:" $steps | sed -e "s/$coltab[.]Needs://"`
|
|---|
| 87 | influences=`grep "$coltab[.]Influences:" $steps | sed -e "s/$coltab[.]Influences://"`
|
|---|
| 88 | primary=fSequenceFirst
|
|---|
| 89 | echo "db: $db - col $col - table $table - coltab $coltab"
|
|---|
| 90 | echo "needs: $needs"
|
|---|
| 91 | echo "influences: $influences"
|
|---|
| 92 | query="select $primary from $table where "
|
|---|
| 93 | for need in $needs
|
|---|
| 94 | do
|
|---|
| 95 | query=$query" not isnull($need) and"
|
|---|
| 96 | done
|
|---|
| 97 | for influence in $influences
|
|---|
| 98 | do
|
|---|
| 99 | query=$query" isnull($influence) and"
|
|---|
| 100 | done
|
|---|
| 101 | query=$query" isnull(fStartTime) and isnull(fFailedTime) and isnull(fFailedCode) and isnull(fFailedCodeAdd) and isnull(fReturnCode) order by $primary desc limit 0, 1 "
|
|---|
| 102 | echo "QUERY: "$query
|
|---|
| 103 | echo ""
|
|---|
| 104 | echo " gettodofiles -> pno"
|
|---|
| 105 |
|
|---|
| 106 | if [ "$pno" == "0" ]
|
|---|
| 107 | then
|
|---|
| 108 | echo " pno = $pno -> continue" #>> $scriptlog 2>&1
|
|---|
| 109 | echo "" #>> $scriptlog 2>&1
|
|---|
| 110 | continue
|
|---|
| 111 | fi
|
|---|
| 112 |
|
|---|
| 113 | y=`date +%Y`
|
|---|
| 114 | m=`date +%m`
|
|---|
| 115 | d=`date +%d`
|
|---|
| 116 | condordir=$logpath/condor/$y/$m/$d
|
|---|
| 117 | makedir $condordir #>> $scriptlog 2>&1
|
|---|
| 118 |
|
|---|
| 119 | echo " ---> starting $pno ${scripts[$i]}..." #>> $scriptlog 2>&1
|
|---|
| 120 |
|
|---|
| 121 | #test
|
|---|
| 122 | echo ""
|
|---|
| 123 | continue
|
|---|
| 124 | #test
|
|---|
| 125 | if ! /usr/local/bin/condor_submit -a path=$scriptspath -a prog=${scripts[$i]} -a y=$y -a m=$m -a d=$d $scriptspath/run.condor 2>$errorlog
|
|---|
| 126 | then
|
|---|
| 127 | date >> $errorlog
|
|---|
| 128 | nail -s 'condor problem' $erradrs < $errorlog
|
|---|
| 129 | echo "condor is not working -> sleeping $errorsleeptime" >> $scriptlog 2>&1
|
|---|
| 130 | sleep $errorsleeptime
|
|---|
| 131 | fi
|
|---|
| 132 | echo "" >> $scriptlog 2>&1
|
|---|
| 133 | done
|
|---|
| 134 | done
|
|---|
| 135 |
|
|---|