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/2006 <mailto:dorner@astro.uni-wuerzburg.de>
|
---|
21 | #
|
---|
22 | # Copyright: MAGIC Software Development, 2000-2006
|
---|
23 | #
|
---|
24 | #
|
---|
25 | # ========================================================================
|
---|
26 | #
|
---|
27 | # This a script, which launches other scripts (all scripts, that are run
|
---|
28 | # on primary basis
|
---|
29 | #
|
---|
30 |
|
---|
31 |
|
---|
32 | source `dirname $0`/sourcefile
|
---|
33 | user=`whoami`
|
---|
34 |
|
---|
35 | set -C
|
---|
36 |
|
---|
37 | echo "" >> $jmscriptlog 2>&1
|
---|
38 | echo "starting jobmanager ("`date`")" >> $jmscriptlog 2>&1
|
---|
39 | makedir $jmlogpath
|
---|
40 | makedir $listpath >> $jmscriptlog 2>&1
|
---|
41 | makedir $lockpath >> $jmscriptlog 2>&1
|
---|
42 |
|
---|
43 | prev=$max
|
---|
44 | notcount=0
|
---|
45 | while (( $notcount < 100 ))
|
---|
46 | do
|
---|
47 | for (( i=0 ; i < ${#scripts[@]} ; i++ ))
|
---|
48 | do
|
---|
49 | makedir $jmlogpath
|
---|
50 | date >> $jmscriptlog 2>&1
|
---|
51 | echo "sleeping $sleeptime..." >> $jmscriptlog 2>&1
|
---|
52 | sleep $sleeptime
|
---|
53 | dayofweek=`date +%u`
|
---|
54 | hour=`date +%k`
|
---|
55 | source `dirname $0`/sourcefile
|
---|
56 | echo "script: ${scripts[$i]}" >> $jmscriptlog 2>&1
|
---|
57 | # echo " day: $dayofweek hour: $hour" >> $jmscriptlog 2>&1
|
---|
58 | queued=`/usr/local/bin/condor_q -global -format "%s\n" Owner | grep -c $user`
|
---|
59 | queued=`setzero $queued`
|
---|
60 | queuedscript=`/usr/local/bin/condor_q -global | grep $user | grep -c ${scripts[$i]}`
|
---|
61 | queuedscript=`setzero $queuedscript`
|
---|
62 | runningscript=`/usr/local/bin/condor_q -global | grep $user | grep ' R ' | grep -c ${scripts[$i]}`
|
---|
63 | runningscript=`setzero $runningscript`
|
---|
64 | stillinqueue=`echo $queuedscript - $runningscript | bc `
|
---|
65 |
|
---|
66 | totalpno=${pnototal[$hour]}
|
---|
67 |
|
---|
68 | #choose array according to the day of the week
|
---|
69 | case $dayofweek in
|
---|
70 | 0 | 6) pnos=( ${pnoswe[@]} ) ;;
|
---|
71 | *) pnos=( ${pnosweek[@]} ) ;;
|
---|
72 | esac
|
---|
73 | num=`echo "((( $i + 1 ) * 24 ) + ( $hour + 1 ) ) - 24 - 1 " | bc `
|
---|
74 | pnoscript=${pnos[$num]}
|
---|
75 | if [ $prev -eq 0 ]
|
---|
76 | then
|
---|
77 | echo " prev=0 => resetting pnoscript [$pnoscript] to max [$max]" >> $jmscriptlog 2>&1
|
---|
78 | pnoscript=$max
|
---|
79 | fi
|
---|
80 | echo " found $queued jobs in the queue (incl. running jobs) [allowed $totalpno]" >> $jmscriptlog 2>&1
|
---|
81 | echo " found $queuedscript ${scripts[$i]} in the queue (incl. running jobs [$runningscript]) [allowed $pnoscript] - not running: $stillinqueue" >> $jmscriptlog 2>&1
|
---|
82 |
|
---|
83 | if [ "$queued" -gt "$totalpno" ]
|
---|
84 | then
|
---|
85 | cont >> $jmscriptlog 2>&1
|
---|
86 | else
|
---|
87 | if [ "$queuedscript" -gt "$pnoscript" ]
|
---|
88 | then
|
---|
89 | cont >> $jmscriptlog 2>&1
|
---|
90 | fi
|
---|
91 | fi
|
---|
92 |
|
---|
93 | # check if there's something to do
|
---|
94 | getstatus >> $jmscriptlog 2>&1
|
---|
95 | echo " $numproc ${scripts[$i]} still do to" >> $jmscriptlog 2>&1
|
---|
96 | if [ "$numproc" = "" ]
|
---|
97 | then
|
---|
98 | prev=0
|
---|
99 | cont >> $jmscriptlog 2>&1
|
---|
100 | fi
|
---|
101 | prev=$max
|
---|
102 | if [ $numproc -lt $stillinqueue ]
|
---|
103 | then
|
---|
104 | echo " numproc($numproc) -lt stillinqueue($stillinqueue)" >> $jmscriptlog 2>&1
|
---|
105 | cont >> $jmscriptlog 2>&1
|
---|
106 | fi
|
---|
107 |
|
---|
108 | date=`date +%Y/%m/%d`
|
---|
109 | date2=`date +%Y-%m-%d`
|
---|
110 | condordir=$logpath/condor/$date
|
---|
111 | makedir $condordir >> $jmscriptlog 2>&1
|
---|
112 |
|
---|
113 | echo " committing 1 ${scripts[$i]} to condor" >> $jmscriptlog 2>&1
|
---|
114 | if ! /usr/local/bin/condor_submit -a path=$scriptspath -a prog=${scripts[$i]} -a date=$date2 -a dir=$condordir $scriptspath/run.condor 2>> $jmerrorlog
|
---|
115 | then
|
---|
116 | date >> $jmerrorlog
|
---|
117 | nail -s 'condor problem' $erradrs < $jmerrorlog
|
---|
118 | echo "condor is not working -> sleeping $errorsleeptime" >> $jmscriptlog 2>&1
|
---|
119 | sleep $errorsleeptime
|
---|
120 | fi
|
---|
121 | date >> $jmscriptlog 2>&1
|
---|
122 | echo "" >> $jmscriptlog 2>&1
|
---|
123 | done
|
---|
124 | done
|
---|
125 |
|
---|