PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 34ms app.codeStats 0ms

/ctdb/events.d/91.lvs

http://github.com/brinkman83/bashrc
Shell | 86 lines | 51 code | 20 blank | 15 comment | 6 complexity | b9721062420276564e6fe1b1ab4f9119 MD5 | raw file
 1#!/bin/sh
 2# script to manage the lvs ip multiplexer for a single public address cluster
 3
 4. $CTDB_BASE/functions
 5
 6loadconfig ctdb
 7
 8[ -z "$CTDB_LVS_PUBLIC_IP" ] && exit 0
 9[ -z "$CTDB_PUBLIC_INTERFACE" ] && exit 0
10
11[ -x /sbin/ipvsadm ] || {
12    echo "LVS configured but /sbin/ipvsadm is not installed."
13    exit 0
14}
15
16case "$1" in 
17     startup)
18	ipvsadm -D -t $CTDB_LVS_PUBLIC_IP:0
19	ipvsadm -D -u $CTDB_LVS_PUBLIC_IP:0
20
21	ip addr add $CTDB_LVS_PUBLIC_IP/32 dev lo scope host >/dev/null 2>/dev/null
22
23	# do not respond to ARPs that are for ip addresses with scope 'host'
24	echo 3 > /proc/sys/net/ipv4/conf/all/arp_ignore
25	# do not send out arp requests from loopback addresses
26	echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
27	;;
28
29     shutdown)
30	ipvsadm -D -t $CTDB_LVS_PUBLIC_IP:0
31	ipvsadm -D -u $CTDB_LVS_PUBLIC_IP:0
32
33	# remove the ip
34	ip addr del $CTDB_LVS_PUBLIC_IP/32 dev lo >/dev/null 2>/dev/null
35
36	# flush our route cache
37	echo 1 > /proc/sys/net/ipv4/route/flush
38	;;
39
40     recovered|stopped)
41	# kill off any tcp connections
42	ipvsadm -D -t $CTDB_LVS_PUBLIC_IP:0
43	ipvsadm -D -u $CTDB_LVS_PUBLIC_IP:0
44	kill_tcp_connections_local_only $CTDB_LVS_PUBLIC_IP
45
46	PNN=`ctdb pnn | sed -e "s/.*PNN://"`
47	LVSMASTER=`ctdb lvsmaster | sed -e "s/.*Node //" -e "s/ .*//"`
48
49	[ "$PNN" != "$LVSMASTER" ] && {
50	    # we are not the lvs master so we have to
51	    # change the ip address to have scope host so we wont respond
52	    # to arps
53	    ip addr del $CTDB_LVS_PUBLIC_IP/32 dev lo >/dev/null 2>/dev/null
54	    ip addr add $CTDB_LVS_PUBLIC_IP/32 dev lo scope host >/dev/null 2>/dev/null
55	    exit 0
56	}
57
58	# change the scope so we start responding to arps
59	ip addr del $CTDB_LVS_PUBLIC_IP/32 dev lo >/dev/null 2>/dev/null
60	ip addr add $CTDB_LVS_PUBLIC_IP/32 dev lo >/dev/null 2>/dev/null
61
62	ipvsadm -A -t $CTDB_LVS_PUBLIC_IP:0 -p 9999 -s lc
63	ipvsadm -A -u $CTDB_LVS_PUBLIC_IP:0 -p 9999 -s lc
64
65	# add all nodes (except ourselves) to the lvs config
66	ctdb lvs | egrep -v "^$PNN:" | sed -e "s/.*://" | while read IP; do
67		ipvsadm -a -t $CTDB_LVS_PUBLIC_IP:0 -r $IP -g
68		ipvsadm -a -u $CTDB_LVS_PUBLIC_IP:0 -r $IP -g
69	done
70	# and add the localhost too
71	ipvsadm -a -t $CTDB_LVS_PUBLIC_IP:0 -r 127.0.0.1
72	ipvsadm -a -u $CTDB_LVS_PUBLIC_IP:0 -r 127.0.0.1
73
74	# send out a gratious arp so our peers will update their arp tables
75	ctdb gratiousarp $CTDB_LVS_PUBLIC_IP $CTDB_PUBLIC_INTERFACE >/dev/null 2>/dev/null
76
77	# flush our route cache
78	echo 1 > /proc/sys/net/ipv4/route/flush
79	;;
80
81    *)
82	ctdb_standard_event_handler "$@"
83	;;
84esac
85
86exit 0