Debian Codegraph @

neutron_ha_tool/primary-backup.template

raw
1 #!/bin/sh
2 #
3 # (C) 2006-2011 by Pablo Neira Ayuso <[email protected]>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # Description:
11 #
12 # This is the script for primary-backup setups for keepalived
13 # (http://www.keepalived.org). You may adapt it to make it work with other
14 # high-availability managers.
15 #
16 # Do not forget to include the required modifications to your keepalived.conf
17 # file to invoke this script during keepalived's state transitions.
18 #
19 # Contributions to improve this script are welcome :).
20 #
21
22 CONNTRACKD_BIN=/usr/sbin/conntrackd
23 CONNTRACKD_LOCK=/var/lock/conntrack.lock
24 CONNTRACKD_CONFIG=/var/lib/neutron/ha_confs/{{ router_id }}/conntrackd.conf
25
26 case "$1" in
27 primary)
28 #
29 # request re-synchronization with peer
30 # Note: attempt to fix problem after reboot of original master,
31 # which had no entries in external cache and so resulted in empty
32 # conntrack table
33 #
34 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -n
35 if [ $? -eq 1 ]
36 then
37 logger "ERROR: failed to invoke conntrackd -n"
38 fi
39
40 #
41 # commit the external cache into the kernel table
42 #
43 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -c
44 if [ $? -eq 1 ]
45 then
46 logger "ERROR: failed to invoke conntrackd -c"
47 fi
48
49 #
50 # flush the internal and the external caches
51 #
52 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -f
53 if [ $? -eq 1 ]
54 then
55 logger "ERROR: failed to invoke conntrackd -f"
56 fi
57
58 #
59 # resynchronize my internal cache to the kernel table
60 #
61 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -R
62 if [ $? -eq 1 ]
63 then
64 logger "ERROR: failed to invoke conntrackd -R"
65 fi
66
67 #
68 # send a bulk update to backups
69 #
70 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -B
71 if [ $? -eq 1 ]
72 then
73 logger "ERROR: failed to invoke conntrackd -B"
74 fi
75 ;;
76 backup)
77 #
78 # is conntrackd running? request some statistics to check it
79 #
80 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -s
81 if [ $? -eq 1 ]
82 then
83 #
84 # something's wrong, do we have a lock file?
85 #
86 if [ -f $CONNTRACKD_LOCK ]
87 then
88 logger "WARNING: conntrackd was not cleanly stopped."
89 logger "If you suspect that it has crashed:"
90 logger "1) Enable coredumps"
91 logger "2) Try to reproduce the problem"
92 logger "3) Post the coredump to [email protected]"
93 rm -f $CONNTRACKD_LOCK
94 fi
95 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -d
96 if [ $? -eq 1 ]
97 then
98 logger "ERROR: cannot launch conntrackd"
99 exit 1
100 fi
101 fi
102 #
103 # shorten kernel conntrack timers to remove the zombie entries.
104 #
105 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -t
106 if [ $? -eq 1 ]
107 then
108 logger "ERROR: failed to invoke conntrackd -t"
109 fi
110
111 #
112 # request resynchronization with master firewall replica (if any)
113 # Note: this does nothing in the alarm approach.
114 #
115 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -n
116 if [ $? -eq 1 ]
117 then
118 logger "ERROR: failed to invoke conntrackd -n"
119 fi
120 ;;
121 fault)
122 #
123 # shorten kernel conntrack timers to remove the zombie entries.
124 #
125 $CONNTRACKD_BIN -C $CONNTRACKD_CONFIG -t
126 if [ $? -eq 1 ]
127 then
128 logger "ERROR: failed to invoke conntrackd -t"
129 fi
130 ;;
131 *)
132 logger "ERROR: unknown state transition"
133 echo "Usage: primary-backup.sh {primary|backup|fault}"
134 exit 1
135 ;;
136 esac
137
138 exit 0
139