From: <abe...@us...> - 2014-11-09 00:42:13
|
Revision: 6810 http://sourceforge.net/p/astlinux/code/6810 Author: abelbeck Date: 2014-11-09 00:42:08 +0000 (Sun, 09 Nov 2014) Log Message: ----------- wan-failover, more tweaks Modified Paths: -------------- branches/1.0/project/astlinux/target_skeleton/etc/init.d/failover branches/1.0/project/astlinux/target_skeleton/etc/udhcpc.script branches/1.0/project/astlinux/target_skeleton/usr/sbin/wan-failover Modified: branches/1.0/project/astlinux/target_skeleton/etc/init.d/failover =================================================================== --- branches/1.0/project/astlinux/target_skeleton/etc/init.d/failover 2014-11-08 22:34:37 UTC (rev 6809) +++ branches/1.0/project/astlinux/target_skeleton/etc/init.d/failover 2014-11-09 00:42:08 UTC (rev 6810) @@ -4,6 +4,7 @@ WAN_LOCKFILE="/var/lock/wan-failover.lock" WAN_PIDFILE="/var/run/wan-failover.pid" +WAN_STARTFILE="/var/run/wan-failover.start" init() { @@ -17,6 +18,8 @@ # Start the background process wan-failover + elif [ -f "$WAN_STARTFILE" ]; then + rm "$WAN_STARTFILE" fi } Modified: branches/1.0/project/astlinux/target_skeleton/etc/udhcpc.script =================================================================== --- branches/1.0/project/astlinux/target_skeleton/etc/udhcpc.script 2014-11-08 22:34:37 UTC (rev 6809) +++ branches/1.0/project/astlinux/target_skeleton/etc/udhcpc.script 2014-11-09 00:42:08 UTC (rev 6810) @@ -71,7 +71,7 @@ done # Restart Failover script if running or enabled and if the gateway changed - if [ -f /var/run/wan-failover.pid -o "$WAN_FAILOVER_ENABLE" = "yes" ]; then + if [ -f /var/run/wan-failover.pid -o -f /var/run/wan-failover.start ]; then if [ "$OLDGW" != "$NEWGW" ]; then /etc/init.d/failover restart >/dev/null 2>&1 & fi Modified: branches/1.0/project/astlinux/target_skeleton/usr/sbin/wan-failover =================================================================== --- branches/1.0/project/astlinux/target_skeleton/usr/sbin/wan-failover 2014-11-08 22:34:37 UTC (rev 6809) +++ branches/1.0/project/astlinux/target_skeleton/usr/sbin/wan-failover 2014-11-09 00:42:08 UTC (rev 6810) @@ -14,6 +14,7 @@ LOCKFILE="/var/lock/wan-failover.lock" PIDFILE="/var/run/wan-failover.pid" +STARTFILE="/var/run/wan-failover.start" STATUSFILE="/var/log/wan-failover-status.log" SCRIPTFILE="/mnt/kd/wan-failover.script" @@ -341,6 +342,9 @@ return 0 } +## Reset flag, when set, on a network change wan-failover should be started if not already running +rm -f "$STARTFILE" + ## Override the 2nd external interface if WAN_FAILOVER_SECONDARY_GW is defined if [ -n "$WAN_FAILOVER_SECONDARY_GW" ]; then EXT2IF="$(ip -o route get $WAN_FAILOVER_SECONDARY_GW | sed -n -r -e 's/^.* dev +([^ ]+).*$/\1/p')" @@ -357,6 +361,28 @@ exit 1 fi +FIRST_TARGET="" +TARGETS="" +unset IFS +for x in $WAN_FAILOVER_TARGETS; do + # Sanitize for manual IPv4 addresses + if [ -z "$(echo "$x" | tr -d '0-9.')" ]; then + TARGETS="$TARGETS${TARGETS:+ }$x" + if [ -z "$FIRST_TARGET" ]; then + FIRST_TARGET="$x" + fi + fi +done +if [ -z "$FIRST_TARGET" ]; then + log_all ERROR "No IPv4 targets to test availability, define: WAN_FAILOVER_TARGETS" + exit 1 +fi + +if ! which fping >/dev/null 2>&1; then + log_all ERROR "The command 'fping' is not available, exiting." + exit 1 +fi + ## PPPoE results in an empty PRIMARY_GW PRIMARY_GW="$(ip route list dev $EXTIF 2>/dev/null | sed -n -r -e 's/^default .*via +([^ ]+).*$/\1/p')" @@ -366,7 +392,8 @@ SECONDARY_GW="$(sed -n -r -e 's/^GW=([0-9.]+).*$/\1/p' "/tmp/udhcpc-${EXT2IF}.conf" | head -n1)" fi if [ -z "$SECONDARY_GW" ]; then - log_all ERROR "Secondary interface gateway not found, exiting." + echo "1" > "$STARTFILE" + log_all ERROR "Secondary interface gateway not found, will restart on a network change." exit 1 fi @@ -376,28 +403,6 @@ SECONDARY_GWIPV6="" fi -if ! which fping >/dev/null 2>&1; then - log_all ERROR "The command 'fping' is not available, exiting." - exit 1 -fi - -FIRST_TARGET="" -TARGETS="" -unset IFS -for x in $WAN_FAILOVER_TARGETS; do - # Sanitize for manual IPv4 addresses - if [ -z "$(echo "$x" | tr -d '0-9.')" ]; then - TARGETS="$TARGETS${TARGETS:+ }$x" - if [ -z "$FIRST_TARGET" ]; then - FIRST_TARGET="$x" - fi - fi -done -if [ -z "$FIRST_TARGET" ]; then - log_all ERROR "No IPv4 targets to test availability, define: WAN_FAILOVER_TARGETS" - exit 1 -fi - if [ "$SECONDARY_GW" = "$(ip route list dev $EXT2IF 2>/dev/null | sed -n -r -e 's|^0.0.0.0/1 .*via +([^ ]+).*$|\1|p')" ]; then ACTIVE_CONNECTION="$SECONDARY_STR" else This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |