#!/bin/bash supernode_off while [ true ] ; do online=$(/bin/cat /etc/supernode-status/supernode.status) mode=$(/bin/cat /etc/supernode-status/supernode.mode) iam=$(/bin/hostname) day=$(date +%d) BATCTL=/usr/local/sbin/batctl #### Settings #### # Names of the 2 Supernodes # if [ $iam = "troisdorf4" ]; then my_SN_IP=185.66.193.104 other_SN_IP=185.66.193.105 other_SN_DNS=5.fftdf.de meship=10.188.0.4 SN1=troisdorf4 SN2=troisdorf5 slack="/usr/local/bin/slacktee.sh -u troisdorf4" elif [ $iam = "troisdorf5" ]; then my_SN_IP=185.66.193.105 other_SN_IP=185.66.193.106 other_SN_DNS=6.fftdf.de meship=10.188.32.5 SN1=troisdorf5 SN2=troisdorf6 slack="/usr/local/bin/slacktee.sh -u troisdorf5" elif [ $iam = "troisdorf6" ]; then my_SN_IP=185.66.193.106 other_SN_IP=185.66.193.104 other_SN_DNS=4.fftdf.de meship=10.188.64.6 SN1=troisdorf6 SN2=troisdorf4 slack="/usr/local/bin/slacktee.sh -u troisdorf6" elif [ $iam = "troisdorf7" ]; then my_SN_IP=185.66.193.107 other_SN_IP=185.66.193.104 other_SN_DNS=4.fftdf.de meship=10.188.92.7 SN1=troisdorf7 SN2=troisdorf4 slack="/usr/local/bin/slacktee.sh -u troisdorf7" fi ################## # functions # # Supernode off # supernode_off () { /usr/local/sbin/batctl gw off /usr/sbin/service bird6 stop /usr/sbin/service bird stop /usr/sbin/service tunneldigger stop /usr/sbin/service tunneldigger-backup stop /usr/sbin/service radvd stop /usr/sbin/service isc-dhcp-server stop echo 0 > /etc/supernode-status/supernode.status echo "collectd.gateways.$iam.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003 } # Supernode on # supernode_on () { /usr/local/sbin/batctl gw server 100Mbit/100Mbit /usr/sbin/service bird6 start /usr/sbin/service bird start /usr/sbin/service tunneldigger start /usr/sbin/service tunneldigger-backup stop /usr/sbin/service radvd start /usr/sbin/service isc-dhcp-server start echo 1 > /etc/supernode-status/supernode.status echo "collectd.gateways.$iam.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003 } # Supernode Backup Mode supernode_backup () { /usr/local/sbin/batctl gw server 100Mbit/100Mbit /usr/sbin/service bird6 start /usr/sbin/service bird start /usr/sbin/service tunneldigger start /usr/sbin/service tunneldigger-backup start /usr/sbin/service radvd start /usr/sbin/service isc-dhcp-server start echo 2 > /etc/supernode-status/supernode.status echo "collectd.gateways.$iam.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003 } # Restart Services # supernode_fail () { /usr/local/sbin/batctl gw off /usr/sbin/service bird6 restart /usr/sbin/service bird restart /usr/sbin/service tunneldigger restart /usr/sbin/service radvd restart /usr/sbin/service isc-dhcp-server restart echo 0 > /etc/supernode-status/supernode.status echo "collectd.gateways.$iam.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003 } #Check other Supernode if [ $mode != "0" ]; then if [ $mode = "1" ]; then nc -zvu $other_SN_DNS 53842 if [ $? -eq 0 ]; then if [ $online = 2 ]; then echo "Supernode wieder online. Backup Modus abgeschaltet" | $slack supernode_on fi else supernode_backup echo "Supernode offline. Backup modus eingeschaltet" | $slack fi fi # Check this Supernode ping -q -c5 $my_SN_IP -I eth0 > /dev/null if [ $? -eq 0 ]; then if [ $online = 0 ]; then echo "Ich bin jetzt Supernode!" | $slack elif [ $mode = 1 ]; then supernode_on elif [ $mode = 2 ]; then supernode_backup fi else supernode_fail echo "Ich konnte mich selbst nicht anpingen. Ich versuche mal die Services neu zu starten" | $slack fi fi # Supernode off if [ $mode = "0" ]; then supernode_off fi # Write Service Status for service in bird bird6 dhcpd radvd python named do x=`pidof $service`; if [ "$x" = "" ]; then echo "collectd.gateways.$iam.$service 0 `date +%s`" | nc -q 0 10.188.1.27 2003 echo 0 > /etc/supernode-status/"$service".status else echo "collectd.gateways.$iam.$service 1 `date +%s`" | nc -q 0 10.188.1.27 2003 echo 1 > /etc/supernode-status/"$service".status fi done # Check DNS Server host google.de $meship if [ "$?" != "0" ]; then service bind9 restart if [ $mode != "0" ]; then echo "DNS Server läuft nicht! Versuche neu zu starten!" | $slack fi fi #Check Tunneldigger Connections if ! [ -d /opt/freifunk/tunneldigger_interfaces ]; then mkdir /opt/freifunk/tunneldigger_interfaces fi #Remove old Interfaces rm /opt/freifunk/tunneldigger_interfaces/* #Create Interace files for i in `/sbin/brctl show br-nodes | grep l2tp`; do touch /opt/freifunk/tunneldigger_interfaces/$i done #Remove wrong file rm /opt/freifunk/tunneldigger_interfaces/no rm /opt/freifunk/tunneldigger_interfaces/br-* rm /opt/freifunk/tunneldigger_interfaces/8* sleep 60 done