merge from ronnie
[metze/ctdb/wip.git] / config / events.d / 10.interface
1 #!/bin/sh
2
3 #################################
4 # interface event script for ctdb
5 # this adds/removes IPs from your 
6 # public interface
7
8 . /etc/ctdb/functions
9 loadconfig ctdb
10
11 cmd="$1"
12 shift
13
14 [ -z "$CTDB_PUBLIC_ADDRESSES" ] && {
15         CTDB_PUBLIC_ADDRESSES=/etc/ctdb/public_addresses
16 }
17
18 [ ! -f "$CTDB_PUBLIC_ADDRESSES" ] && {
19         echo "No public addresses file found. Nothing to do for 10.interfaces"
20         exit 0
21 }
22
23 case $cmd in 
24      #############################
25      # called when ctdbd starts up
26      startup)
27         # make sure that we only respond to ARP messages from the NIC where
28         # a particular ip address is associated.
29         echo 1 > /proc/sys/ipv4/conf/all/arp_filter
30         ;;
31
32
33      ################################################
34      # called when ctdbd wants to claim an IP address
35      takeip)
36         if [ $# != 3 ]; then
37            echo "must supply interface, IP and maskbits"
38            exit 1
39         fi
40         iface=$1
41         ip=$2
42         maskbits=$3
43
44         # we make sure the interface is up first
45         /sbin/ip link set $iface up || {
46                  echo "`/bin/date` Failed to bringup interface $iface"
47                  exit 1
48         }
49         /sbin/ip addr del $ip/32 dev lo >/dev/null 2>/dev/null
50         /sbin/ip addr add $ip/$maskbits dev $iface || {
51                  echo "`/bin/date` Failed to add $ip/$maskbits on dev $iface"
52                  exit 1
53         }
54
55         # flush our route cache
56         echo 1 > /proc/sys/net/ipv4/route/flush
57         ;;
58
59
60      ##################################################
61      # called when ctdbd wants to release an IP address
62      releaseip)
63         if [ $# != 3 ]; then
64            echo "`/bin/date` must supply interface, IP and maskbits"
65            exit 1
66         fi
67         iface=$1
68         ip=$2
69         maskbits=$3
70         /sbin/ip addr del $ip/$maskbits dev $iface || {
71                  echo "`/bin/date` Failed to del $ip on dev $iface"
72                  exit 1
73         }
74         /sbin/ip addr add $ip/32 dev lo >/dev/null 2>/dev/null
75
76         # flush our route cache
77         echo 1 > /proc/sys/net/ipv4/route/flush
78         ;;
79
80
81      ###########################################
82      # called when ctdbd has finished a recovery
83      recovered)
84         ;;
85
86      ####################################
87      # called when ctdbd is shutting down
88      shutdown)
89         ;;
90
91      monitor)
92         [ -x /usr/sbin/ethtool ] && {
93                 cat $CTDB_PUBLIC_ADDRESSES | sed -e "s/^[^\t ]*[\t ]*//" -e "s/[\t ]*$//" | sort | uniq | while read IFACE; do
94                         /usr/sbin/ethtool $IFACE | grep 'Link detected: yes' > /dev/null || {
95                                 echo "`date` ERROR: No link on the public network interface $IFACE"
96                                 exit 1
97                         }
98                 done
99         }
100         ;;
101
102 esac
103
104 exit 0
105
106
107