Correct CARP events on devd and the argument processing on called scripts

This commit is contained in:
Ermal 2013-12-02 21:12:31 +00:00
parent aa87cf1108
commit 77411fa70d
3 changed files with 32 additions and 16 deletions

View File

@ -14,16 +14,14 @@ options {
# CARP notify hooks. This will call carpup/carpdown with the
# interface (carp0, carp1) as the first parameter.
notify 100 {
match "system" "IFNET";
match "type" "LINK_UP";
match "subsystem" "[a-zA-Z0-9_]+_vip[0-9]+";
match "system" "CARP";
match "type" "MASTER";
action "/etc/rc.carpmaster $subsystem";
};
notify 100 {
match "system" "IFNET";
match "type" "LINK_DOWN";
match "subsystem" "[a-zA-Z0-9_]+_vip[0-9]+";
match "system" "CARP";
match "type" "BACKUP";
action "/etc/rc.carpbackup $subsystem";
};

View File

@ -35,21 +35,30 @@ require_once("notices.inc");
require_once("openvpn.inc");
require_once("interfaces.inc");
$notificationmsg = sprintf('Carp cluster member "%2$s (%1$s)" has resumed the state "BACKUP"',$argv[1],convert_friendly_interface_to_friendly_descr($argv[1]));
$argument = str_replace("\n", "", $argv[1]);
if (!strstr($argument, "@"))
log_error("Carp MASTER event triggered from wrong source {$argument}");
list($vhid, $iface) = explode("@", $argument);
$friendly = convert_real_interface_to_friendly_interface_name($iface);
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
$notificationmsg = sprintf('Carp cluster member "%2$s (%1$s)" has resumed the state "BACKUP"', $argument, $friendly_descr);
notify_via_smtp($notificationmsg);
notify_via_growl($notificationmsg);
log_error($notificationmsg);
/* Stop OpenVPN clients running on this VIP, since multiple active OpenVPN clients on a CARP cluster can be problematic. */
global $config;
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
foreach ($config['openvpn']['openvpn-client'] as $settings) {
if ($settings['interface'] == $argv[1]) {
log_error("Stopping OpenVPN instance on {$settings['interface']} because of transition to CARP backup.");
if ($settings['interface'] == $friendly) {
log_error("Stopping OpenVPN client instance on {$friendly_descr} because of transition to CARP backup.");
openvpn_restart('client', $settings);
}
}
}
?>
?>

View File

@ -35,28 +35,37 @@ require_once("notices.inc");
require_once("openvpn.inc");
require_once("interfaces.inc");
$notificationmsg = sprintf('Carp cluster member "%2$s (%1$s)" has resumed the state "MASTER"',$argv[1],convert_friendly_interface_to_friendly_descr($argv[1]));
$argument = str_replace("\n", "", $argv[1]);
if (!strstr($argument, "@"))
log_error("Carp MASTER event triggered from wrong source {$argument}");
list($vhid, $iface) = explode("@", $argument);
$friendly = convert_real_interface_to_friendly_interface_name($iface);
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
$notificationmsg = sprintf('Carp cluster member "%2$s (%1$s)" has resumed the state "MASTER"', $argument, $friendly_descr);
notify_via_smtp($notificationmsg);
notify_via_growl($notificationmsg);
log_error($notificationmsg);
/* Start OpenVPN clients running on this VIP, since they should be in the stopped state while the VIP is CARP Backup. */
global $config;
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
foreach ($config['openvpn']['openvpn-client'] as $settings) {
if ($settings['interface'] == $argv[1]) {
log_error("Starting OpenVPN instance on {$settings['interface']} because of transition to CARP master.");
if ($settings['interface'] == $friendly) {
log_error("Starting OpenVPN client instance on {$friendly_descr} because of transition to CARP master.");
openvpn_restart('client', $settings);
}
}
}
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
foreach ($config['openvpn']['openvpn-server'] as $settings) {
if ($settings['interface'] == $argv[1]) {
log_error("Starting OpenVPN instance on {$settings['interface']} because of transition to CARP master.");
if ($settings['interface'] == $friendly) {
log_error("Starting OpenVPN instance on {$friendly_descr} because of transition to CARP master.");
openvpn_restart('server', $settings);
}
}
}
?>
?>