#!/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 [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