#!/bin/sh #FLIP1405 - Failover Server Solution #RUN ON PRIMARY ASTERISK SERVER #AUTHOR-GREGG HANSEN 20080208 #DEPENDENCIES: nmap, arping # #Do a find and replace on the following IP with your Virtual IP #192.168.5.30 = VIRTUAL IP STATUS=$(nmap -p 5060 -sU 127.0.0.1 | awk '{print $2}' | grep open) #if Local Asterisk up = 'open|filtered' PRIMARYIP=$(ifconfig eth0:1 | grep 192.168.5.30 | awk '{print $2}' | sed 's/addr://g') #if primary owns virtual = '192.168.5.30' VIRTUALIP=$(nmap -sP 192.168.5.30 | grep down | awk '{print $4}') #if virtual is not pingable = 'down.' if [ "$STATUS" == "open|filtered" ] ; then ###is primary asterisk up? if [ "$PRIMARYIP" != "192.168.5.30" ] ; then ###does primary not own virtual ip? if [ "$VIRTUALIP" == "down." ] ; then ###is the virtual IP not pingable? ifconfig eth0:1 192.168.5.30/24 up arping -U -c 5 -I eth0 192.168.5.30 ###Gratuitous ARP request fi fi else service asterisk start ifconfig eth0:1 down fi