#!/bin/sh /etc/rc.common
# Copyright (C) 2013-2014 ****email****
START=99
STOP=11
#DHCP Server's IP
DS=192.168.0.102
#Refer to /etc/config/dhcp
InterfaceName=lan
CheckInterval=27
use_syslog=1
use_varlog=1
log=/var/log/dhcp_failover.csv
PID=/var/run/dhcp_failover.pid
lastDSstatus=-1
dhcp_failover_logger()
{
if [ "$use_syslog" = 1 ]
then
logger -t dhcp_failover[$] $*
fi
if [ "$use_varlog" = 1 ]
then
echo $*>>$log
fi
}
start() {
if [ -e $PID ] ; then
dhcp_failover_logger $(date +"%F,%T"),Dhcp_failover is already running.
else
echo [ DISCUZ_CODE_2 ]gt;$PID
dhcp_failover_logger $(date +"%F,%T"),Process $ is starting.
while [ true ]
do
ping -w 2 $DS >/dev/null
DSstatus=$?
if [ $lastDSstatus -ne $DSstatus ] ; then
if [ $lastDSstatus -ne -1 ] ; then
dhcp_failover_logger $(date +"%F,%T"),The status of $DS has been changed.
fi
NewIgnoreFlag=$DSstatus
uci get dhcp.$InterfaceName.ignore
OldIgnoreFlag=$?
if [ $OldIgnoreFlag -ne $NewIgnoreFlag ] ; then
if [ $NewIgnoreFlag -eq 0 ] ; then
uci set dhcp.$InterfaceName.ignore=1
else
if [ $NewIgnoreFlag -eq 1 ] ; then
uci delete dhcp.$InterfaceName.ignore
fi
fi
dhcp_failover_logger $(date +"%F,%T"),Setting $(uci changes dhcp).
uci commit dhcp
/etc/init.d/dnsmasq restart
sleep 1
dhcp_failover_logger $(date +%F,%T),Dnsmasq\'s pid is $(cat /var/run/dnsmasq.pid).
fi
fi
lastDSstatus=$DSstatus
sleep $CheckInterval
done
fi
}
stop() {
if [ -e $PID ] ; then
kill -9 $(cat $PID)
rm -f $PID
dhcp_failover_logger $(date +"%F,%T"),Dhcp_failover has been killed.
else
dhcp_failover_logger $(date +"%F,%T"),Dhcp_failover is NOT running.
fi
}
restart() {
stop
dhcp_failover_logger $(date +"%F,%T"),Dhcp_failover is restarting.
start
}