Ejemplo n.º 1
0
    def openvpn_watch(self):
        try:
            while True:
                while True:
                    line = self.process.stdout.readline()
                    if not line:
                        if self.process.poll() is not None:
                            break
                        else:
                            time.sleep(0.05)
                            continue

                    yield

                    try:
                        self.server.output_link.push_output(
                            line,
                            label=self.output_label,
                            link_server_id=self.linked_server.id,
                        )
                    except:
                        logger.exception(
                            'Failed to push link vpn ' + 'output',
                            'server',
                            server_id=self.server.id,
                        )

                    yield

                if self.stop_event.is_set():
                    break
                else:
                    logger.error(
                        'Server instance link stopped ' +
                        'unexpectedly, restarting link',
                        'server',
                        server_id=self.server.id,
                        link_server_id=self.linked_server.id,
                    )
                    self.openvpn_start()
                    yield interrupter_sleep(1)

            yield

        finally:
            if self.interface:
                utils.tun_interface_release(self.interface)
                self.interface = None
            utils.rmtree(self._temp_path)
Ejemplo n.º 2
0
 def stop_watch(self):
     try:
         while True:
             if self.stop_event.wait(1):
                 return
             yield
     finally:
         try:
             if not utils.stop_process(self.process):
                 logger.error('Failed to stop openvpn link process. %r' % {
                     'server_id': self.server.id,
                 })
         finally:
             if self.interface:
                 utils.tun_interface_release(self.interface)
                 self.interface = None
Ejemplo n.º 3
0
    def openvpn_watch(self):
        try:
            while True:
                while True:
                    line = self.process.stdout.readline()
                    if not line:
                        if self.process.poll() is not None:
                            break
                        else:
                            time.sleep(0.05)
                            continue

                    yield

                    try:
                        self.server.output_link.push_output(
                            line,
                            label=self.output_label,
                            link_server_id=self.linked_server.id,
                        )
                    except:
                        logger.exception('Failed to push link vpn ' +
                            'output', 'server',
                            server_id=self.server.id,
                        )

                    yield

                if self.stop_event.is_set():
                    break
                else:
                    logger.error('Server instance link stopped ' +
                        'unexpectedly, restarting link', 'server',
                        server_id=self.server.id,
                        link_server_id=self.linked_server.id,
                    )
                    self.openvpn_start()
                    yield interrupter_sleep(1)

            yield

        finally:
            if self.interface:
                utils.tun_interface_release(self.interface)
                self.interface = None
            utils.rmtree(self._temp_path)
Ejemplo n.º 4
0
 def stop_watch(self):
     try:
         while True:
             if self.stop_event.wait(1):
                 return
             yield
     finally:
         try:
             if not utils.stop_process(self.process):
                 logger.error('Failed to stop openvpn link process',
                     'server',
                     server_id=self.server.id,
                 )
         finally:
             if self.interface:
                 utils.tun_interface_release(self.interface)
                 self.interface = None
Ejemplo n.º 5
0
 def resources_release(self):
     if self.resource_lock:
         self.resource_lock.release()
         utils.tun_interface_release(self.interface)
         self.interface = None
Ejemplo n.º 6
0
 def resources_release(self):
     if self.resource_lock:
         self.resource_lock.release()
         utils.tun_interface_release(self.interface)
         self.interface = None