ansible.fftdf.supernode/files/keepalive.exit.sh.j2

104 lines
3.3 KiB
Plaintext
Raw Normal View History

2016-02-27 23:13:18 +00:00
#!/bin/bash
2016-03-12 16:02:49 +00:00
echo 0 > /tmp/sn_online
2016-03-13 16:35:08 +00:00
$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
2016-03-05 13:34:33 +00:00
while [ true ] ; do
2016-03-12 16:02:49 +00:00
online=$(/bin/cat /tmp/sn_online)
iam=$(/bin/hostname)
day=$(date +%d)
BATCTL=/usr/local/sbin/batctl
#### Settings ####
# Names of the 2 Supernodes #
SN1=troisdorf5
SN2=troisdorf6
# Default Supernode if loadbalance=0 or day > 15 #
active_SN=$SN2
# Turn loadbalance on/off #
loadbalance=1
##################
# 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
echo 0 > /tmp/sn_online
2016-03-13 16:35:08 +00:00
echo "collectd.gateways.{{ sn_hostname }}.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
2016-03-05 12:57:32 +00:00
}
2016-03-12 16:02:49 +00:00
# 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
echo 1 > /tmp/sn_online
2016-03-13 16:35:08 +00:00
echo "collectd.gateways.{{ sn_hostname }}.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
2016-03-12 16:02:49 +00:00
}
# 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 > /tmp/sn_online
2016-03-13 16:35:08 +00:00
echo "collectd.gateways.{{ sn_hostname }}.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
2016-03-12 16:02:49 +00:00
}
# who am i ? #
if [ $iam == troisdorf5 ]
2016-02-27 23:13:18 +00:00
then
2016-03-12 16:02:49 +00:00
my_SN_IP=185.66.193.105
other_SN_IP=185.66.193.106
else
my_SN_IP=185.66.193.106
other_SN_IP=185.66.193.105
2016-02-27 23:13:18 +00:00
fi
2016-03-12 16:02:49 +00:00
if [ $loadbalance == 1 ]
2016-02-27 23:13:18 +00:00
then
2016-03-12 16:02:49 +00:00
if [ $day -gt 15 ]
then
active_SN=$SN1
fi
2016-02-27 23:13:18 +00:00
fi
2016-03-12 16:02:49 +00:00
#Check other Supernode
if [ $iam != $active_SN ]
2016-02-27 23:13:18 +00:00
then
2016-03-12 16:02:49 +00:00
ping -q -c5 $other_SN_IP -I eth0 > /dev/null
if [ $? -eq 0 ]
then
if [ $online == 1 ]; then
supernode_off
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
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 900
fi
2016-02-27 23:13:18 +00:00
else
2016-03-12 16:02:49 +00:00
# Check this Supernode
ping -q -c5 $my_SN_IP -I eth0 > /dev/null
if [ $? -eq 0 ]
then
if [ $online == 0 ]; then
supernode_on
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
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
2016-02-27 23:13:18 +00:00
fi
2016-03-12 16:02:49 +00:00
sleep 60
2016-03-05 13:34:33 +00:00
done