Keepalive changes

This commit is contained in:
Stefan Hoffmann 2016-03-12 17:02:49 +01:00
parent 4254a646e9
commit 7220630539

View File

@ -1,81 +1,96 @@
#!/bin/bash #!/bin/bash
#Variablen echo 0 > /tmp/sn_online
while [ true ] ; do while [ true ] ; do
supernode_off () { online=$(/bin/cat /tmp/sn_online)
$BATCTL gw off iam=$(/bin/hostname)
/usr/sbin/service bird6 stop day=$(date +%d)
/usr/sbin/service bird stop BATCTL=/usr/local/sbin/batctl
/usr/sbin/service tunneldigger stop #### Settings ####
/usr/sbin/service radvd stop # Names of the 2 Supernodes #
echo "Active Supernode is running" SN1=troisdorf5
} SN2=troisdorf6
# Default Supernode if loadbalance=0 or day > 15 #
supernode_on () { active_SN=$SN2
$BATCTL gw server 100Mbit/100Mbit # Turn loadbalance on/off #
/usr/sbin/service bird6 start loadbalance=1
/usr/sbin/service bird start ##################
/usr/sbin/service tunneldigger start # functions #
/usr/sbin/service radvd start # 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
} }
# Supernode on #
supernode_fail () { supernode_on () {
$BATCTL gw off $BATCTL gw server 100Mbit/100Mbit
/usr/sbin/service bird6 restart /usr/sbin/service bird6 start
/usr/sbin/service bird restart /usr/sbin/service bird start
/usr/sbin/service tunneldigger restart /usr/sbin/service tunneldigger start
/usr/sbin/service radvd restart /usr/sbin/service radvd start
echo "Supernode nicht pingbar" /usr/sbin/service isc-dhcp-server start
} echo 1 > /tmp/sn_online
}
iam=$(/bin/hostname) # Restart Services #
BATCTL=/usr/local/sbin/batctl supernode_fail () {
SN1=troisdorf5 $BATCTL gw off
SN2=troisdorf6 /usr/sbin/service bird6 restart
if [ $iam == troisdorf5 ] /usr/sbin/service bird restart
then /usr/sbin/service tunneldigger restart
my_SN_IP=185.66.193.105 /usr/sbin/service radvd restart
other_SN_IP=185.66.193.106 /usr/sbin/service isc-dhcp-server restart
else echo 0 > /tmp/sn_online
my_SN_IP=185.66.193.106 }
other_SN_IP=185.66.193.105 # who am i ? #
fi if [ $iam == troisdorf5 ]
#Auf 1 setzen um Lastverteilung 1/2 Monat einzuschalten
loadbalance=1
#Default Supernode if loadbalance=0
active_SN=$SN2
day=$(date +%d)
if [ $loadbalance == 1 ]
then
if [ $day -gt 15 ]
then then
active_SN=$SN1 my_SN_IP=185.66.193.105
fi other_SN_IP=185.66.193.106
fi
#Check other Supernode
if [ $iam != $active_SN ]
then
ping -q -c5 $other_SN_IP -I eth0 > /dev/null
if [ $? -eq 0 ]
then
supernode_off
else else
supernode_on my_SN_IP=185.66.193.106
echo "First Supernode not running!" other_SN_IP=185.66.193.105
curl -X POST --data-urlencode 'payload={"text": "Aktiver Supernode nicht pingbar. {{ sn_hostname }} eingeschaltet", "channel": "#technik", "username": "{{ sn_hostname }}", "icon_emoji": ":warning:"}' https://hooks.slack.com/services/{{ slack_token }}
sleep 900
fi fi
else if [ $loadbalance == 1 ]
# Check this Supernode
ping -q -c5 $my_SN_IP -I eth0 > /dev/null
if [ $? -eq 0 ]
then then
echo "Supernode ok" if [ $day -gt 15 ]
supernode_on then
else active_SN=$SN1
echo "Supernode nicht pingbar" fi
supernode_fail
curl -X POST --data-urlencode 'payload={"text": "{{ sn_hostname }} nicht pingbar. services auf {{ sn_hostname }} neu gestartet", "channel": "#technik", "username": "{{ sn_hostname }}", "icon_emoji": ":warning:"}' https://hooks.slack.com/services/{{ slack_token }}
fi fi
fi #Check other Supernode
sleep 60 if [ $iam != $active_SN ]
then
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
else
# 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
fi
# Push to Graphite #
echo "collectd.gateways.{{ sn_hostname }}.sn-status $online `date +%s`" | nc -q 0 10.188.1.27 2003
sleep 60
done done