132 lines
4.4 KiB
Django/Jinja
132 lines
4.4 KiB
Django/Jinja
#!/bin/bash
|
|
/usr/local/sbin/batctl gw off
|
|
/usr/sbin/service bird6 stop
|
|
/usr/sbin/service bird stop
|
|
/usr/sbin/service tunneldigger stop
|
|
/usr/sbin/service radvd stop
|
|
/usr/sbin/service isc-dhcp-server stop
|
|
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 #
|
|
SN1=troisdorf5
|
|
SN2=troisdorf6
|
|
active_SN=$(/bin/hostname)
|
|
# Turn loadbalance on/off #
|
|
loadbalance=$(cat /etc/supernode-status/loadbalancing.mode)
|
|
##################
|
|
# functions #
|
|
# Supernode off #
|
|
supernode_off () {
|
|
$BATCTL gw off
|
|
/usr/sbin/service bird6 stop
|
|
/usr/sbin/service bird stop
|
|
/usr/sbin/service tunneldigger stop
|
|
/usr/sbin/service radvd stop
|
|
/usr/sbin/service isc-dhcp-server stop
|
|
if [ $loadbalance == 1 ] && [ $mode != 0 ]; then
|
|
echo 3 > /etc/supernode-status/supernode.status
|
|
else
|
|
echo 0 > /etc/supernode-status/supernode.status
|
|
fi
|
|
echo "collectd.gateways.troisdorf5.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
|
|
}
|
|
# Supernode on #
|
|
supernode_on () {
|
|
$BATCTL gw server 100Mbit/100Mbit
|
|
/usr/sbin/service bird6 start
|
|
/usr/sbin/service bird start
|
|
/usr/sbin/service tunneldigger start
|
|
/usr/sbin/service radvd start
|
|
/usr/sbin/service isc-dhcp-server start
|
|
if [ $loadbalance == 1 ]; then
|
|
echo 1 > /etc/supernode-status/supernode.status
|
|
else
|
|
echo 2 > /etc/supernode-status/supernode.status
|
|
fi
|
|
echo "collectd.gateways.troisdorf5.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
|
|
}
|
|
# Restart Services #
|
|
supernode_fail () {
|
|
$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.troisdorf5.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
|
|
}
|
|
# who am i ? #
|
|
if [ $iam = "troisdorf5" ];
|
|
then
|
|
my_SN_IP=185.66.193.105
|
|
other_SN_IP=185.66.193.106
|
|
other_SN_IP_EXTERN=46.4.138.189
|
|
else
|
|
my_SN_IP=185.66.193.106
|
|
other_SN_IP=185.66.193.105
|
|
other_SN_IP_EXTERN=5.9.76.198
|
|
fi
|
|
if [ $loadbalance = "1" ] && [ $mode != "0" ];
|
|
then
|
|
if [ $day -gt 15 ]
|
|
then
|
|
active_SN=$SN1
|
|
else
|
|
active_SN=$SN2
|
|
fi
|
|
fi
|
|
#Check other Supernode
|
|
if [ $iam != $active_SN ];
|
|
then
|
|
ping -q -c5 $other_SN_IP -I eth0 > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
if [ $online ==1 ] || [ $online = 2 ]; then
|
|
curl -X POST --data-urlencode 'payload={"text": "Aktiver Supernode wieder online. Ich habe mich wieder ausgeschaltet", "channel": "#technik", "username": "{{ sn_hostname }}", "icon_emoji": ":white_check_mark:"}' https://hooks.slack.com/services/{{ slack_token }}
|
|
fi
|
|
supernode_off
|
|
else
|
|
supernode_on
|
|
curl -X POST --data-urlencode 'payload={"text": "Aktiver Supernode offline. Ich habe mich eingeschaltet", "channel": "#technik", "username": "{{ sn_hostname }}", "icon_emoji": ":warning:"}' https://hooks.slack.com/services/{{ slack_token }}
|
|
sleep 300
|
|
fi
|
|
else
|
|
# Check this Supernode
|
|
if [ $mode != "0" ]; then
|
|
ping -q -c5 $my_SN_IP -I eth0 > /dev/null
|
|
if [ $? -eq 0 ]
|
|
then
|
|
if [ $online = 0 ] || [ $online = 3 ]; then
|
|
curl -X POST --data-urlencode 'payload={"text": "Ich bin jetzt Supernode!", "channel": "#technik", "username": "{{ sn_hostname }}", "icon_emoji": ":white_check_mark:"}' https://hooks.slack.com/services/{{ slack_token }}
|
|
fi
|
|
supernode_on
|
|
else
|
|
supernode_fail
|
|
curl -X POST --data-urlencode 'payload={"text": "Ich konnte mich selbst nicht anpingen. Ich versuche mal die Services neu zu starten", "channel": "#technik", "username": "{{ sn_hostname }}", "icon_emoji": ":warning:"}' https://hooks.slack.com/services/{{ slack_token }}
|
|
fi
|
|
fi
|
|
fi
|
|
if [ $mode = "0" ]; then
|
|
supernode_off
|
|
|
|
fi
|
|
for service in bird bird6 isc-dhcp-server radvd python named
|
|
do
|
|
x=`pidof $service`;
|
|
if [ "$x" = "" ]; then
|
|
echo "collectd.gateways.troisdorf5.$service 0 `date +%s`" | nc -q 0 10.188.1.27 2003
|
|
echo 0 > /etc/supernode-status/"$service".status
|
|
else
|
|
echo "collectd.gateways.troisdorf5.$service 1 `date +%s`" | nc -q 0 10.188.1.27 2003
|
|
echo 1 > /etc/supernode-status/"$service".status
|
|
fi
|
|
done
|
|
sleep 60
|
|
done
|