ctdb-tests: Use default public addresses file for event script tests
[samba.git] / ctdb / config / events.d / 10.external
1 #!/bin/sh
2
3 # Eventscript for CTDB to cope with externally managed public IP addresses
4
5 # If DisableIPFailover is set:
6 #
7 # * 10.interface must be disabled.
8 # * For connection tracking/killing to work this script must be enabled.
9
10 [ -n "$CTDB_BASE" ] || \
11     CTDB_BASE=$(d=$(dirname "$0") ; cd -P "$d" ; dirname "$PWD")
12
13 . "${CTDB_BASE}/functions"
14
15 loadconfig
16
17 if [ -z "$CTDB_PUBLIC_ADDRESSES" ] ; then
18     exit 0
19 fi
20
21 if [ ! -f "$CTDB_PUBLIC_ADDRESSES" ] ; then
22     if [ "$1" = "init" ]; then
23         echo "No public addresses file found. Nothing to do for 10.interfaces.external"
24     fi
25     exit 0
26 fi
27
28 takeover_assigned_ips ()
29 {
30     _pnn=$(ctdb_get_pnn)
31
32     $CTDB -X ip |
33     awk -F'|' '{print $2}' |
34     while read ip ; do
35         _ip_details=$(ip_maskbits_iface "$ip")
36         if [ -n "$_ip_details" ] ; then
37             echo "Assigning $ip to this node (${_pnn})"
38             $CTDB moveip "$ip" "$_pnn"
39         fi
40     done
41 }
42
43 ctdb_check_args "$@"
44
45 case "$1" in
46     startup)
47         takeover_assigned_ips
48         ;;
49 esac
50
51 exit 0