From ecdf0404b73d024a16f60bd35fd5f2f08401a8b0 Mon Sep 17 00:00:00 2001 From: Franco Fichtner Date: Mon, 29 Apr 2019 09:25:01 +0200 Subject: [PATCH] openvpn: deflect a carp event ealier for servers If the server is running don't stop it. If it is not running go through the trouble of trying to start it. --- src/etc/inc/plugins.inc.d/openvpn.inc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/etc/inc/plugins.inc.d/openvpn.inc b/src/etc/inc/plugins.inc.d/openvpn.inc index d21a3a854..2b7f9a102 100644 --- a/src/etc/inc/plugins.inc.d/openvpn.inc +++ b/src/etc/inc/plugins.inc.d/openvpn.inc @@ -981,20 +981,21 @@ function openvpn_restart($mode, $settings, $carp_event = false) $vpnid = $settings['vpnid']; $mode_id = $mode.$vpnid; + if ($carp_event && $mode == 'server' && isvalidpid("/var/run/openvpn_{$mode_id}.pid")) { + /* do not stop or restart a server if we are handling a CARP event */ + return; + } + killbypid("/var/run/openvpn_{$mode_id}.pid", 'TERM', true); if (isset($settings['disable'])) { return; } - if (strstr($settings['interface'], '_vip')) { - if ($mode == 'client' && get_carp_interface_status($settings['interface']) == gettext('BACKUP')) { - /* do not start a client if we are a CARP backup instance */ + if (strstr($settings['interface'], '_vip') && $mode == 'client' && + get_carp_interface_status($settings['interface']) == gettext('BACKUP')) { + /* do not restart a client if we are a CARP backup instance */ return; - } elseif ($mode == 'server' && $carp_event) { - /* do not start a server if we are handling a CARP event */ - return; - } } @unlink("/var/etc/openvpn/{$mode_id}.sock");