blob: e77b7645b358cd37b470faf5badfdb73eeb990e9 (
plain)
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
#!/bin/bash
# This script is meant to be called automatically by dnsmasq's dhcp-script directive
# but it can also be used to manage the manual insertion and deletion of nodes.
# Make sure dnsmasq doesn't come an play against you though.
MODULESPATH=%%MODULESPATH
BEEPS=%%BEEPS
beeps(){
### Beeps:
PAUSE=20
START=200
STOP=2000
STEP=200
BEEP_add="$(for I in `seq $START $STEP $STOP`; do echo -n " -f $I -l $PAUSE -r 1 -n"; done)"
BEEP_del="$(for I in `seq $STOP -$STEP $START`; do echo -n " -f $I -l $PAUSE -r 1 -n"; done)"
BEEP_add="beep ${BEEP_add%%-n}"
BEEP_del="beep ${BEEP_del%%-n}"
eval \$BEEP_$COMMAND
}
run_modules(){
for I in ${MODULESPATH}/*-${COMMAND}
do
$I $@ $DNSMASQ_USER_CLASS0
done
[[ $BEEPS == "true" ]] && beeps
}
# Yes, it's crude but we'll elaborate later on something more functionnal
# ...say something based on Avahi with live beakons
node_is_alive(){
ping -c 1 -w 1 $HNAME
return $?
}
# Nodes can either be added or removed. For a thorough description of the mechanism, see
# dnsmasq's manpage section concerning dhcp-script
old_node(){
shift
if [[ node_is_alive ]]; then
$0 add $*
else
$0 del $*
fi
}
usage(){
echo "$0 is called as follows:"
echo "$0 <add|del> <MAC address> <IP address> <hostname> <processor count> [number of processors]"
echo "If [number of processors] is not set, the default one is used from the clustering config file when needed."
}
##### Variables #######
COMMAND=$1
MACADDR=$2
IP=$3
HNAME=$4
##### Variables END ###
if [[ $COMMAND == "del" ]]; then
run_modules $@
else
# we background this since it performs a ping with a 1 second timeout
# on a 256 node system, those seconds add up...
if [[ $# -lt 5 ]]; then
# We ignore calls made with only 4 args as we're missing the processor count.
# This can be caused by dnsmasq reloading or dnsmasq not setting DNSMASQ_USER_CLASS0
# as the incoming request is either only a "renewal/rebind" request which doesnt trigger
# DHCPDISCOVER
exit 0
elif [[ $COMMAND == "old" ]]; then
old_node $@ &
else # COMMAND == add
run_modules $@
fi
fi
exit 0
|