aboutsummaryrefslogtreecommitdiffstats
path: root/Tools/portbuild/scripts/checkmachines
blob: c242c33149c8ea3f4b1858e56daa153f4a314d47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/bin/sh
#
# Runs in the background on the server.  This script keeps track of
# the relative loads of the client machines, and specifies which machine(s)
# should be handed new jobs, according to the following algorithm:
#
# For each machine listed in ${buildroot}/mlist, check whether its load
# information has been updated in the last 15 seconds (should be updated by
# the reportload script every 5 seconds).  If so, then divide the number of
# running jobs on the client by its weighting in mlist, and output the
# machine(s) with the minimum value to ${buildroot}/ulist. 
#
# Dividing by the weight has the effect of grouping machines with similar
# job load (e.g. a weight of 5 will rank machines with job loads 0, 1, 2, 3, 4
# as the same; if the machines all had a weight of 1 then it would only
# choose the machine with the least value of the job load, and would probably
# choose a single machine most of the time).

buildroot=/var/portbuild
mlist=${buildroot}/mlist
stamp=${buildroot}/loads/.stamp

unset DISPLAY

while true; do
  touch ${stamp}
  sleep 15
  min=99
  set $(cat $mlist)
  while [ $# -gt 1 ]; do
    m=$1
    l=$2
    if [ -f ${buildroot}/loads/$m -a \
      ! -z "$(find ${buildroot}/loads/$m -newer ${stamp})" ]; then
      num=$(awk '{print $1}' ${buildroot}/loads/$m)
      if [ "x$num" = "x" ]; then
#   logger "checkmachines: file ${buildroot}/loads/$m is empty"
    num=99
      fi
    else
      num=99
    fi
#xxx
#xxx Need to figure out how this is happening and fix this script
#xxx accordingly.  This is what causes this script to go away on
#xxx occasion.
#xxx
#xxx arith: syntax error: "7:53AM / 5"
#xxx
    num=$(($num / $l))
    if [ $num -lt $min ]; then
      mach=$m
      min=$num
    elif [ $num = $min ]; then
      mach="$mach $m"
    fi
    shift 2
  done
  echo "$mach" > ${buildroot}/ulist
done