2016-02-27 23:13:18 +00:00
|
|
|
#!/bin/bash
|
2016-05-13 21:40:55 +00:00
|
|
|
supernode_off
|
2016-03-05 13:34:33 +00:00
|
|
|
while [ true ] ; do
|
2016-04-17 21:11:57 +00:00
|
|
|
online=$(/bin/cat /etc/supernode-status/supernode.status)
|
|
|
|
mode=$(/bin/cat /etc/supernode-status/supernode.mode)
|
2016-03-12 16:02:49 +00:00
|
|
|
iam=$(/bin/hostname)
|
|
|
|
day=$(date +%d)
|
|
|
|
BATCTL=/usr/local/sbin/batctl
|
|
|
|
#### Settings ####
|
|
|
|
# Names of the 2 Supernodes #
|
2016-05-28 11:26:53 +00:00
|
|
|
if [ $iam = "troisdorf4" ]; then
|
|
|
|
my_SN_IP=185.66.193.104
|
|
|
|
other_SN_IP=185.66.193.105
|
2016-06-02 21:21:02 +00:00
|
|
|
other_SN_DNS=5.fftdf.de
|
2016-05-28 11:26:53 +00:00
|
|
|
meship=10.188.0.4
|
|
|
|
SN1=troisdorf4
|
|
|
|
SN2=troisdorf5
|
2016-06-04 16:39:59 +00:00
|
|
|
slack="/usr/local/bin/slacktee.sh -u troisdorf4"
|
2016-05-28 11:26:53 +00:00
|
|
|
elif [ $iam = "troisdorf5" ]; then
|
2016-05-06 19:38:11 +00:00
|
|
|
my_SN_IP=185.66.193.105
|
|
|
|
other_SN_IP=185.66.193.106
|
2016-06-02 21:21:02 +00:00
|
|
|
other_SN_DNS=6.fftdf.de
|
2016-05-28 11:26:53 +00:00
|
|
|
meship=10.188.32.5
|
2016-05-13 21:40:55 +00:00
|
|
|
SN1=troisdorf5
|
|
|
|
SN2=troisdorf6
|
2016-06-04 16:39:59 +00:00
|
|
|
slack="/usr/local/bin/slacktee.sh -u troisdorf5"
|
2016-05-13 21:40:55 +00:00
|
|
|
elif [ $iam = "troisdorf6" ]; then
|
2016-05-06 19:38:11 +00:00
|
|
|
my_SN_IP=185.66.193.106
|
2016-06-02 21:21:02 +00:00
|
|
|
other_SN_IP=185.66.193.104
|
|
|
|
other_SN_DNS=4.fftdf.de
|
2016-05-28 11:26:53 +00:00
|
|
|
meship=10.188.64.6
|
|
|
|
SN1=troisdorf6
|
2016-06-02 21:21:02 +00:00
|
|
|
SN2=troisdorf4
|
2016-06-04 16:39:59 +00:00
|
|
|
slack="/usr/local/bin/slacktee.sh -u troisdorf6"
|
2016-05-28 11:26:53 +00:00
|
|
|
elif [ $iam = "troisdorf7" ]; then
|
|
|
|
my_SN_IP=185.66.193.107
|
|
|
|
other_SN_IP=185.66.193.104
|
2016-06-02 21:21:02 +00:00
|
|
|
other_SN_DNS=4.fftdf.de
|
2016-05-28 11:26:53 +00:00
|
|
|
meship=10.188.92.7
|
|
|
|
SN1=troisdorf7
|
|
|
|
SN2=troisdorf4
|
2016-06-04 16:39:59 +00:00
|
|
|
slack="/usr/local/bin/slacktee.sh -u troisdorf7"
|
2016-05-06 19:38:11 +00:00
|
|
|
fi
|
|
|
|
##################
|
|
|
|
# functions #
|
|
|
|
# Supernode off #
|
2016-03-12 16:02:49 +00:00
|
|
|
supernode_off () {
|
2016-06-06 20:10:52 +00:00
|
|
|
/usr/local/sbin/batctl gw off
|
2016-03-12 16:02:49 +00:00
|
|
|
/usr/sbin/service bird6 stop
|
|
|
|
/usr/sbin/service bird stop
|
|
|
|
/usr/sbin/service tunneldigger stop
|
2016-05-29 10:30:30 +00:00
|
|
|
/usr/sbin/service tunneldigger-backup stop
|
2016-03-12 16:02:49 +00:00
|
|
|
/usr/sbin/service radvd stop
|
|
|
|
/usr/sbin/service isc-dhcp-server stop
|
2016-05-28 11:26:53 +00:00
|
|
|
echo 0 > /etc/supernode-status/supernode.status
|
2016-05-06 19:38:11 +00:00
|
|
|
echo "collectd.gateways.$iam.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
|
2016-03-05 12:57:32 +00:00
|
|
|
}
|
2016-05-06 19:38:11 +00:00
|
|
|
# Supernode on #
|
2016-03-12 16:02:49 +00:00
|
|
|
supernode_on () {
|
2016-06-06 20:10:52 +00:00
|
|
|
/usr/local/sbin/batctl gw server 100Mbit/100Mbit
|
2016-03-12 16:02:49 +00:00
|
|
|
/usr/sbin/service bird6 start
|
|
|
|
/usr/sbin/service bird start
|
|
|
|
/usr/sbin/service tunneldigger start
|
2016-05-28 11:26:53 +00:00
|
|
|
/usr/sbin/service tunneldigger-backup stop
|
2016-03-12 16:02:49 +00:00
|
|
|
/usr/sbin/service radvd start
|
|
|
|
/usr/sbin/service isc-dhcp-server start
|
2016-05-28 11:26:53 +00:00
|
|
|
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 () {
|
2016-06-06 20:10:52 +00:00
|
|
|
/usr/local/sbin/batctl gw server 100Mbit/100Mbit
|
2016-05-28 11:26:53 +00:00
|
|
|
/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
|
2016-05-06 19:38:11 +00:00
|
|
|
echo "collectd.gateways.$iam.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
|
2016-03-12 16:02:49 +00:00
|
|
|
}
|
2016-05-06 19:38:11 +00:00
|
|
|
# Restart Services #
|
2016-03-12 16:02:49 +00:00
|
|
|
supernode_fail () {
|
2016-06-06 20:10:52 +00:00
|
|
|
/usr/local/sbin/batctl gw off
|
2016-03-12 16:02:49 +00:00
|
|
|
/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
|
2016-04-17 21:11:57 +00:00
|
|
|
echo 0 > /etc/supernode-status/supernode.status
|
2016-05-06 19:38:11 +00:00
|
|
|
echo "collectd.gateways.$iam.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
|
2016-03-12 16:02:49 +00:00
|
|
|
}
|
2016-05-06 19:38:11 +00:00
|
|
|
#Check other Supernode
|
2016-06-04 16:39:59 +00:00
|
|
|
if [ $mode != "0" ]; then
|
2016-06-06 20:10:52 +00:00
|
|
|
if [ $mode = "1" ]; then
|
2016-07-11 17:35:03 +00:00
|
|
|
/bin/nc -zvu $other_SN_DNS 53842
|
2016-06-04 16:39:59 +00:00
|
|
|
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
|
2016-03-12 16:02:49 +00:00
|
|
|
fi
|
2016-05-06 19:38:11 +00:00
|
|
|
# Check this Supernode
|
2016-07-11 17:35:03 +00:00
|
|
|
/bin/ping -q -c5 $my_SN_IP -I eth0 > /dev/null
|
2016-06-04 16:39:59 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
if [ $online = 0 ]; then
|
|
|
|
echo "Ich bin jetzt Supernode!" | $slack
|
2016-06-06 20:10:52 +00:00
|
|
|
elif [ $mode = 1 ]; then
|
2016-06-04 16:39:59 +00:00
|
|
|
supernode_on
|
2016-06-06 20:10:52 +00:00
|
|
|
elif [ $mode = 2 ]; then
|
2016-06-04 16:39:59 +00:00
|
|
|
supernode_backup
|
2016-04-17 21:11:57 +00:00
|
|
|
fi
|
2016-06-04 16:39:59 +00:00
|
|
|
else
|
|
|
|
supernode_fail
|
|
|
|
echo "Ich konnte mich selbst nicht anpingen. Ich versuche mal die Services neu zu starten" | $slack
|
2016-03-12 16:02:49 +00:00
|
|
|
fi
|
2016-06-04 16:39:59 +00:00
|
|
|
fi
|
2016-05-06 19:38:11 +00:00
|
|
|
# Supernode off
|
2016-04-17 21:11:57 +00:00
|
|
|
if [ $mode = "0" ]; then
|
|
|
|
supernode_off
|
|
|
|
fi
|
2016-05-06 19:38:11 +00:00
|
|
|
# Write Service Status
|
2016-05-01 16:23:43 +00:00
|
|
|
for service in bird bird6 dhcpd radvd python named
|
2016-03-19 12:03:23 +00:00
|
|
|
do
|
|
|
|
x=`pidof $service`;
|
2016-04-17 21:11:57 +00:00
|
|
|
if [ "$x" = "" ]; then
|
2016-06-04 16:39:59 +00:00
|
|
|
echo "collectd.gateways.$iam.$service 0 `date +%s`" | nc -q 0 10.188.1.27 2003
|
|
|
|
echo 0 > /etc/supernode-status/"$service".status
|
2016-03-19 12:03:23 +00:00
|
|
|
else
|
2016-06-04 16:39:59 +00:00
|
|
|
echo "collectd.gateways.$iam.$service 1 `date +%s`" | nc -q 0 10.188.1.27 2003
|
|
|
|
echo 1 > /etc/supernode-status/"$service".status
|
2016-03-19 12:03:23 +00:00
|
|
|
fi
|
|
|
|
done
|
2016-05-06 19:38:11 +00:00
|
|
|
# Check DNS Server
|
2016-07-11 17:35:03 +00:00
|
|
|
/usr/bin/host google.de $meship
|
2016-05-06 19:38:11 +00:00
|
|
|
if [ "$?" != "0" ]; then
|
|
|
|
service bind9 restart
|
2016-06-04 16:39:59 +00:00
|
|
|
if [ $mode != "0" ]; then
|
|
|
|
echo "DNS Server läuft nicht! Versuche neu zu starten!" | $slack
|
|
|
|
fi
|
2016-05-06 19:38:11 +00:00
|
|
|
fi
|
|
|
|
#Check Tunneldigger Connections
|
2016-05-03 08:23:09 +00:00
|
|
|
if ! [ -d /opt/freifunk/tunneldigger_interfaces ]; then
|
2016-05-06 19:38:11 +00:00
|
|
|
mkdir /opt/freifunk/tunneldigger_interfaces
|
2016-05-03 08:23:09 +00:00
|
|
|
fi
|
2016-05-06 19:38:11 +00:00
|
|
|
#Remove old Interfaces
|
2016-05-03 08:23:09 +00:00
|
|
|
rm /opt/freifunk/tunneldigger_interfaces/*
|
2016-05-06 19:38:11 +00:00
|
|
|
#Create Interace files
|
2016-05-03 08:23:09 +00:00
|
|
|
for i in `/sbin/brctl show br-nodes | grep l2tp`;
|
|
|
|
do
|
|
|
|
touch /opt/freifunk/tunneldigger_interfaces/$i
|
|
|
|
done
|
2016-05-06 19:38:11 +00:00
|
|
|
#Remove wrong file
|
2016-05-03 08:23:09 +00:00
|
|
|
rm /opt/freifunk/tunneldigger_interfaces/no
|
|
|
|
rm /opt/freifunk/tunneldigger_interfaces/br-*
|
|
|
|
rm /opt/freifunk/tunneldigger_interfaces/8*
|
2016-03-12 16:02:49 +00:00
|
|
|
sleep 60
|
2016-03-05 13:34:33 +00:00
|
|
|
done
|