Revision 7de4474e
Added by Luiz Souza over 9 years ago
src/etc/rc.carpbackup | ||
---|---|---|
34 | 34 |
require_once("openvpn.inc"); |
35 | 35 |
require_once("interfaces.inc"); |
36 | 36 |
|
37 |
if (isset($_GET)) { |
|
37 |
if (isset($_GET['interface'])) {
|
|
38 | 38 |
$argument = $_GET['interface']; |
39 | 39 |
} else { |
40 | 40 |
$argument = str_replace("\n", "", $argv[1]); |
41 | 41 |
} |
42 | 42 |
if (!strstr($argument, "@")) { |
43 | 43 |
log_error("CARP master event triggered from wrong source {$argument}"); |
44 |
exit; |
|
44 | 45 |
} |
45 | 46 |
|
46 | 47 |
list($vhid, $iface) = explode("@", $argument); |
... | ... | |
48 | 49 |
$friendly = convert_real_interface_to_friendly_interface_name($iface); |
49 | 50 |
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly); |
50 | 51 |
$vips = link_interface_to_vips($friendly, '', $vhid); |
51 |
$carp_iface = "{$friendly}_vip{$vhid}"; |
|
52 |
|
|
53 |
if (is_array($vips)) { |
|
54 |
foreach ($vips as $vip) { |
|
55 |
$notificationmsg = sprintf('HA cluster member "(%1$s): (%2$s)" has resumed CARP state "BACKUP" for vhid %3$s', $argument, $friendly_descr, $vhid); |
|
52 |
if (!is_array($vips)) { |
|
53 |
log_error("CARP master event triggered from wrong source {$argument} - no associated VIPs"); |
|
54 |
exit; |
|
55 |
} |
|
56 |
foreach ($vips as $vip) { |
|
57 |
$notificationmsg = sprintf('HA cluster member "(%1$s@%2$s): (%3$s)" has resumed CARP state "BACKUP" for vhid %4$s', |
|
58 |
$vip['subnet'], $iface, $friendly_descr, $vhid); |
|
56 | 59 |
|
57 |
notify_via_smtp($notificationmsg); |
|
58 |
notify_via_growl($notificationmsg); |
|
59 |
log_error($notificationmsg); |
|
60 |
} |
|
60 |
notify_via_smtp($notificationmsg); |
|
61 |
notify_via_growl($notificationmsg); |
|
62 |
log_error($notificationmsg); |
|
61 | 63 |
} |
62 | 64 |
|
63 | 65 |
/* Stop OpenVPN clients running on this VIP, since multiple active OpenVPN clients on a CARP cluster can be problematic. */ |
... | ... | |
85 | 87 |
} |
86 | 88 |
} |
87 | 89 |
|
88 |
/* Reconfigure radvd when necessary */ |
|
89 |
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) { |
|
90 |
$found = false; |
|
91 |
foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) { |
|
92 |
if ($dhcpv6ifconf['rainterface'] != $carp_iface) { |
|
93 |
continue; |
|
90 |
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) { |
|
91 |
foreach ($config['openvpn']['openvpn-server'] as $settings) { |
|
92 |
foreach ($vips as $vip) { |
|
93 |
if ($settings['interface'] == "_vip{$vip['uniqid']}") { |
|
94 |
log_error("Stopping OpenVPN instance on {$friendly_descr} because of transition to CARP backup."); |
|
95 |
openvpn_restart('server', $settings); |
|
96 |
} |
|
94 | 97 |
} |
95 |
|
|
96 |
$found = true; |
|
97 |
break; |
|
98 |
} |
|
99 |
|
|
100 |
if ($found === true) { |
|
101 |
services_radvd_configure(); |
|
102 | 98 |
} |
103 | 99 |
} |
104 | 100 |
|
src/etc/rc.carpmaster | ||
---|---|---|
34 | 34 |
require_once("openvpn.inc"); |
35 | 35 |
require_once("interfaces.inc"); |
36 | 36 |
|
37 |
if (isset($_GET)) { |
|
37 |
if (isset($_GET['interface'])) {
|
|
38 | 38 |
$argument = $_GET['interface']; |
39 | 39 |
} else { |
40 | 40 |
$argument = str_replace("\n", "", $argv[1]); |
41 | 41 |
} |
42 | 42 |
if (!strstr($argument, "@")) { |
43 | 43 |
log_error("CARP master event triggered from wrong source {$argument}"); |
44 |
exit; |
|
44 | 45 |
} |
45 | 46 |
|
46 | 47 |
list($vhid, $iface) = explode("@", $argument); |
... | ... | |
48 | 49 |
$friendly = convert_real_interface_to_friendly_interface_name($iface); |
49 | 50 |
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly); |
50 | 51 |
$vips = link_interface_to_vips($friendly, '', $vhid); |
51 |
$carp_iface = "{$friendly}_vip{$vhid}"; |
|
52 |
if (!is_array($vips)) { |
|
53 |
log_error("CARP master event triggered from wrong source {$argument} - no associated VIPs"); |
|
54 |
exit; |
|
55 |
} |
|
52 | 56 |
foreach ($vips as $vip) { |
53 |
$notificationmsg = sprintf('HA cluster member "(%1$s): (%2$s)" has resumed CARP state "MASTER" for vhid %3$s', $argument, $friendly_descr, $vhid); |
|
57 |
$notificationmsg = sprintf('HA cluster member "(%1$s@%2$s): (%3$s)" has resumed CARP state "MASTER" for vhid %4$s', |
|
58 |
$vip['subnet'], $iface, $friendly_descr, $vhid); |
|
54 | 59 |
|
55 | 60 |
notify_via_smtp($notificationmsg); |
56 | 61 |
notify_via_growl($notificationmsg); |
... | ... | |
83 | 88 |
} |
84 | 89 |
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) { |
85 | 90 |
foreach ($config['openvpn']['openvpn-server'] as $settings) { |
86 |
if ($settings['interface'] == $carp_iface) { |
|
87 |
log_error("Starting OpenVPN instance on {$friendly_descr} because of transition to CARP master."); |
|
88 |
openvpn_restart('server', $settings); |
|
89 |
} |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
/* Reconfigure radvd when necessary */ |
|
94 |
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) { |
|
95 |
$found = false; |
|
96 |
foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) { |
|
97 |
if ($dhcpv6ifconf['rainterface'] != $carp_iface) { |
|
98 |
continue; |
|
91 |
foreach ($vips as $vip) { |
|
92 |
if ($settings['interface'] == "_vip{$vip['uniqid']}") { |
|
93 |
log_error("Starting OpenVPN instance on {$friendly_descr} because of transition to CARP master."); |
|
94 |
openvpn_restart('server', $settings); |
|
95 |
} |
|
99 | 96 |
} |
100 |
|
|
101 |
$found = true; |
|
102 |
break; |
|
103 |
} |
|
104 |
|
|
105 |
if ($found === true) { |
|
106 |
services_radvd_configure(); |
|
107 | 97 |
} |
108 | 98 |
} |
109 | 99 |
|
Also available in: Unified diff
Fix the rc.carpmaster and rc.carpbackup scripts.
Now, they look for main CARP IP and IP aliases running on supplied vhid.