ctdb-scripts: Quote some variable expansions
[nivanova/samba-autobuild/.git] / ctdb / config / events.d / 11.routing
index 06741939e53c832b320c81f916c9c8144f12f9ea..87c0027124bdd4bd56c968c84f33667134f966f5 100755 (executable)
@@ -1,37 +1,53 @@
 #!/bin/sh
-# script to add entries to the routing table after we have performed a
-# take ip event
-# (when we do a "releaseip" event and remove an ip address from an interface
-#  the kernel might automatically remove associated entries from
-#  the routing table. This is where we add them back)
+
+# Attempt to add a set of static routes.
+#
+# Do this in "ipreallocated" rather than just "startup" because some
+# of the routes might be missing because the corresponding interface
+# has not previously had any IPs assigned or IPs were previously
+# released and corresponding routes were dropped.
+#
+# Addition of some routes might fail, errors go to /dev/null.
+#
+# Routes to add are defined in $CTDB_BASE/static-routes. Syntax is:
 #
-# Routes to add are defined in /etc/ctdb/static-routes.
-# Syntax is :
 # IFACE NET/MASK GATEWAY
 #
-# Example
+# Example:
+#
 # bond1 10.3.3.0/24 10.0.0.1
 
-. $CTDB_BASE/functions
-loadconfig ctdb
+[ -n "$CTDB_BASE" ] || \
+    CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
 
-[ -f $CTDB_BASE/static-routes ] || {
+. "${CTDB_BASE}/functions"
+
+loadconfig
+
+[ -f "${CTDB_BASE}/static-routes" ] || {
     exit 0
 }
 
-cmd="$1"
-shift
-PATH=/usr/bin:/bin:/usr/sbin:/sbin:$PATH
-
-case $cmd in 
-     takeip|releaseip)
-       iface=$1
-       cat $CTDB_BASE/static-routes | egrep "^$iface " | while read IFACE DEST GW; do
-           ip route add $DEST via $GW dev $IFACE >/dev/null 2>/dev/null
-       done
+case "$1" in
+    ipreallocated)
+        while read iface dest gw; do
+            ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
+        done <"${CTDB_BASE}/static-routes"
+        ;;
 
+    updateip)
+       oiface=$2
+       niface=$3
+       while read iface dest gw; do
+           if [ "$niface" = "$iface" -o "$oiface" = "$iface" ] ; then
+               ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
+           fi
+       done <"${CTDB_BASE}/static-routes"
        ;;
 
+    *)
+       ctdb_standard_event_handler "$@"
+       ;;
 esac
 
 exit 0