From 116af66d410ee3a4ee69a8fa25c6036ed1c2411f Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Thu, 24 Aug 2017 01:31:23 -0400 Subject: [refactor] restart by allowing to send SIGUSR1 to openvpn process by properly allowing openvpn to restart when receiving SIGUSR1, we can reserve the hard process restarts for cases in which the process is aborted. this depends on bitmask-root adding --persist-tun and --persist-key as mandatory/allowed parameters. --- src/leap/bitmask/vpn/tunnel.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/leap/bitmask/vpn/tunnel.py') diff --git a/src/leap/bitmask/vpn/tunnel.py b/src/leap/bitmask/vpn/tunnel.py index d9a8be3..7c2274a 100644 --- a/src/leap/bitmask/vpn/tunnel.py +++ b/src/leap/bitmask/vpn/tunnel.py @@ -31,8 +31,6 @@ from .process import VPNProcess # TODO ----------------- refactor -------------------- -# [ ] register change state listener -# emit_async(catalog.VPN_STATUS_CHANGED) # [ ] catch ping-restart # 'NETWORK_UNREACHABLE': ( # 'Network is unreachable (code=101)',), @@ -40,6 +38,8 @@ from .process import VPNProcess # "SIGTERM[soft,tls-error]",), # TODO ----------------- refactor -------------------- +RESTART_WAIT = 2 # in secs + class ConfiguredTunnel(object): @@ -82,8 +82,8 @@ class ConfiguredTunnel(object): defer.returnValue(started) @defer.inlineCallbacks - def stop(self): - stopped = yield self._stop_vpn(restart=False) + def stop(self, restart=False): + stopped = yield self._stop_vpn(restart=restart) defer.returnValue(stopped) # status @@ -110,14 +110,14 @@ class ConfiguredTunnel(object): vpnproc = VPNProcess(*args, **kwargs) self._vpnproc = vpnproc - self.__start_pre_up(vpnproc) - cmd = self.__start_get_cmd(vpnproc) - - running = yield self.__start_spawn_proc(vpnproc, cmd) - if running: + try: + self.__start_pre_up(vpnproc) + cmd = self.__start_get_cmd(vpnproc) + running = yield self.__start_spawn_proc(vpnproc, cmd) vpnproc.pid = running.pid defer.returnValue(True) - else: + except Exception: + # TODO need to propagate the error message properly. defer.returnValue(False) def __start_pre_up(self, proc): @@ -150,7 +150,7 @@ class ConfiguredTunnel(object): def _restart_vpn(self): yield self.stop(restart=True) reactor.callLater( - self.RESTART_WAIT, self.start) + RESTART_WAIT, self.start) @defer.inlineCallbacks def _stop_vpn(self, restart=False): -- cgit v1.2.3