From bd55a85af79d6e16b511f2f07b87582fb5dd3ced Mon Sep 17 00:00:00 2001 From: Viacheslav Date: Wed, 12 Jan 2022 15:56:52 +0000 Subject: op-vpn: T4168: Add timeout for restart vpn with nhrp With command "restart vpn" in some cases charon process is not fully loaded when is used DMVPN. It is impossible to load "swanctl -q" configuration while "charon" not loaded Add timeout and wait until charon will be available, after that load swanctl configuration --- scripts/vyatta-vpn-op.pl | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/vyatta-vpn-op.pl b/scripts/vyatta-vpn-op.pl index 3be7fd8..b48bbb5 100755 --- a/scripts/vyatta-vpn-op.pl +++ b/scripts/vyatta-vpn-op.pl @@ -65,6 +65,18 @@ if ($op eq 'clear-vpn-ipsec-process') { # Check if nhrp configuration exists, exit code # As 'restart vpn' doesn't load nhrp configuration T3846 if (system('cli-shell-api existsActive protocols nhrp') == 0) { + # Set a small timeout for waiting for charon will be loaded + # 0 => process not found, 1 => process found + my $timeout = 7; + if (system("pgrep charon | wc -l" eq 0)) { + while ($timeout >= 1){ + sleep(1); + if (system("pgrep charon | wc -l" eq 1)){ + last; + } + $timeout--; + } + } system 'sudo swanctl --load-all'; } } else { -- cgit v1.2.3