eventscripts: Each script should set CTDB_BASE if it is not set
[nivanova/samba-autobuild/.git] / ctdb / config / events.d / 11.routing
1 #!/bin/sh
2 # script to add entries to the routing table after we have performed a
3 # take ip event
4 # (when we do a "releaseip" event and remove an ip address from an interface
5 #  the kernel might automatically remove associated entries from
6 #  the routing table. This is where we add them back)
7 #
8 # Routes to add are defined in /etc/ctdb/static-routes.
9 # Syntax is :
10 # IFACE NET/MASK GATEWAY
11 #
12 # Example
13 # bond1 10.3.3.0/24 10.0.0.1
14
15 [ -n "$CTDB_BASE" ] || \
16     export CTDB_BASE=$(cd -P $(dirname "$0") ; dirname "$PWD")
17
18 . $CTDB_BASE/functions
19 loadconfig
20
21 [ -f $CTDB_BASE/static-routes ] || {
22     exit 0
23 }
24
25 case "$1" in
26     recovered|ipreallocated)
27         while read iface dest gw; do
28             ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
29         done <"${CTDB_BASE}/static-routes"
30         ;;
31
32     updateip)
33         oiface=$2
34         niface=$3
35         while read iface dest gw; do
36             if [ "$niface" = "$iface" -o "$oiface" = "$iface" ] ; then
37                 ip route add "$dest" via "$gw" dev "$iface" >/dev/null 2>&1
38             fi
39         done <"${CTDB_BASE}/static-routes"
40         ;;
41
42     *)
43         ctdb_standard_event_handler "$@"
44         ;;
45 esac
46
47 exit 0