ea28eb70451b1062410234499f10f1d1fb00779a
[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
10 cmd="$1"
11 shift
12
13 case $cmd in 
14      #############################
15      # called when ctdbd starts up
16      startup)
17         ;;
18
19
20      ################################################
21      # called when ctdbd wants to claim an IP address
22      takeip)
23         if [ $# != 3 ]; then
24            echo "must supply interface, IP and maskbits"
25            exit 1
26         fi
27         iface=$1
28         ip=$2
29         maskbits=$3
30
31         # we make sure the interface is up first
32         /sbin/ip link set $iface up || {
33                  echo "`/bin/date` Failed to bringup interface $iface"
34                  exit 1
35         }
36         /sbin/ip addr add $ip/$maskbits dev $iface || {
37                  echo "`/bin/date` Failed to add $ip/$maskbits on dev $iface"
38                  exit 1
39         }
40
41         # flush our route cache
42         echo 1 > /proc/sys/net/ipv4/route/flush
43         ;;
44
45
46      ##################################################
47      # called when ctdbd wants to release an IP address
48      releaseip)
49         if [ $# != 3 ]; then
50            echo "`/bin/date` must supply interface, IP and maskbits"
51            exit 1
52         fi
53         iface=$1
54         ip=$2
55         maskbits=$3
56         /sbin/ip addr del $ip dev $iface || {
57                  echo "`/bin/date` Failed to del $ip on dev $iface"
58                  exit 1
59         }
60
61         # flush our route cache
62         echo 1 > /proc/sys/net/ipv4/route/flush
63         ;;
64
65
66      ###########################################
67      # called when ctdbd has finished a recovery
68      recovered)
69         ;;
70
71      ####################################
72      # called when ctdbd is shutting down
73      shutdown)
74         ;;
75
76 esac
77
78 exit 0