diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/conf_mode/ipsec-settings.py | 24 | ||||
-rwxr-xr-x | src/conf_mode/vpn_l2tp.py | 1 |
2 files changed, 11 insertions, 14 deletions
diff --git a/src/conf_mode/ipsec-settings.py b/src/conf_mode/ipsec-settings.py index 0599bf101..a9885f3d3 100755 --- a/src/conf_mode/ipsec-settings.py +++ b/src/conf_mode/ipsec-settings.py @@ -17,12 +17,11 @@ import re import os -from time import sleep from sys import exit from vyos.config import Config from vyos import ConfigError -from vyos.util import call +from vyos.util import call, wait_for_file_write_complete from vyos.template import render from vyos import airbag @@ -197,17 +196,16 @@ def generate(data): remove_confs(delim_ipsec_l2tp_begin, delim_ipsec_l2tp_end, ipsec_conf_file) def restart_ipsec(): - call('ipsec restart >&/dev/null') - # counter for apply swanctl config - counter = 10 - while counter <= 10: - if os.path.exists(charon_pidfile): - call('swanctl -q >&/dev/null') - break - counter -=1 - sleep(1) - if counter == 0: - raise ConfigError('VPN configuration error: IPSec is not running.') + try: + wait_for_file_write_complete(charon_pidfile, + pre_hook=(lambda: call('ipsec restart >&/dev/null')), + timeout=10) + + # Force configuration load + call('swanctl -q >&/dev/null') + + except OSError: + raise ConfigError('VPN configuration error: IPSec process did not start.') def apply(data): # Restart IPSec daemon diff --git a/src/conf_mode/vpn_l2tp.py b/src/conf_mode/vpn_l2tp.py index e970d2ef5..9c52f77ca 100755 --- a/src/conf_mode/vpn_l2tp.py +++ b/src/conf_mode/vpn_l2tp.py @@ -20,7 +20,6 @@ import re from copy import deepcopy from stat import S_IRUSR, S_IWUSR, S_IRGRP from sys import exit -from time import sleep from ipaddress import ip_network |