def force_stop(self, silent=False): cache_db.lock_acquire(self.get_cache_key('op_lock')) try: if not self.status: return logger.debug('Forcing stop server. %r' % { 'server_id': self.id, }) stopped = False self.publish('force_stop') for message in cache_db.subscribe(self.get_cache_key(), SUB_RESPONSE_TIMEOUT): if message == 'stopped': stopped = True break if not stopped: raise ServerStopError('Server thread failed to return ' + \ 'stop event', { 'server_id': self.id, }) if not silent: Event(type=SERVERS_UPDATED) LogEntry(message='Stopped server "%s".' % self.name) finally: cache_db.lock_release(self.get_cache_key('op_lock'))
def stop(self, silent=False): if not self.status: return try: response = self._request('delete') if response.status_code != 200: raise ServerStopError('Failed to stop node server', { 'server_id': self.id, 'status_code': response.status_code, 'reason': response.reason, }) except httplib.HTTPException: logger.exception('Failed to delete stopped node server', { 'server_id': self.id, }) if self.status: stopped = False self.publish('stop') for message in cache_db.subscribe(self.get_cache_key(), HTTP_COM_REQUEST_TIMEOUT + 3): if message == 'stopped': stopped = True break if not stopped: raise ServerStopError('Server thread failed to return ' + \ 'stop event', { 'server_id': self.id, }) if not silent: Event(type=SERVERS_UPDATED) LogEntry(message='Stopped server "%s".' % self.name)
def start(self): temp_path = app_server.get_temp_path() if not self.org_count: raise ServerMissingOrg('Server cannot be started ' + \ 'without any organizations', { 'server_id': self.id, }) os.makedirs(temp_path) ovpn_conf_path = self._generate_ovpn_conf(temp_path) self._enable_ip_forwarding() self._set_iptables_rules() self.clear_output() threading.Thread(target=self._run_thread, args=(temp_path,)).start() started = False for message in cache_db.subscribe(self.get_cache_key(), SUB_RESPONSE_TIMEOUT): if message == 'started': started = True break elif message == 'stopped': raise ServerStartError('Server failed to start', { 'server_id': self.id, }) if not started: raise ServerStartError('Server thread failed to return ' + \ 'start event', { 'server_id': self.id, })
def _sub_thread(self): for message in cache_db.subscribe(self.get_cache_key()): try: if message == 'stop': self._interrupt = True elif message == 'stopped': break except OSError: pass
def _fill_servers_thread(self): self._fill_servers() for msg in cache_db.subscribe('pooler'): if msg == 'update': time.sleep(2) self._fill_servers() elif msg == 'stop': return
def _sub_thread(self, process): for message in cache_db.subscribe(self.get_cache_key()): try: if message == 'stop': process.send_signal(signal.SIGINT) elif message == 'force_stop': process.send_signal(signal.SIGKILL) elif message == 'stopped': break except OSError: pass
def sub_thread(): for message in cache_db.subscribe(self.get_cache_key()): try: if message == 'stop': self._state = False if self._ws: self._ws.close() elif message == 'stopped': break except OSError: pass
def sub_thread(): for message in cache_db.subscribe(self.get_cache_key()): try: if message == 'stop': thread_data['state'] = False ws = thread_data.get('ws') if ws: ws.close() elif message == 'stopped': break except OSError: pass
def force_stop(self): if not self.status: return logger.debug('Forcing stop server. %r' % { 'server_id': self.id, }) stopped = False self.publish('force_stop') for message in cache_db.subscribe(self.get_cache_key(), SUB_RESPONSE_TIMEOUT): if message == 'stopped': stopped = True break if not stopped: raise ValueError('Server thread failed to return stop event.')
def _fill_servers_pool_listener(self, cache_key, dh_param_path, process): for msg in cache_db.subscribe('pooler'): if msg == 'update': if process.poll() is not None: break elif cache_db.set_length('openssl_tasks') and \ cache_db.set_exists(cache_key, dh_param_path): # There is a running openssl process started by the user # which takes priority over the pooler's dhparam process if process.poll() is None: process.terminate() time.sleep(0.3) if process.poll() is None: process.kill() elif msg == 'stop': process.kill() return
def stop(self, silent=False): if not self.status: return stopped = False self.publish('stop') for message in cache_db.subscribe(self.get_cache_key(), SUB_RESPONSE_TIMEOUT): if message == 'stopped': stopped = True break if not stopped: raise ServerStopError('Server thread failed to return ' + \ 'stop event', { 'server_id': self.id, }) if not silent: Event(type=SERVERS_UPDATED) LogEntry(message='Stopped server "%s".' % self.name)
def start(self, silent=False): cache_db.lock_acquire(self.get_cache_key('op_lock')) try: if self.status: return if not self.org_count: raise ServerMissingOrg('Server cannot be started without ' + \ 'any organizations', { 'server_id': self.id, }) logger.debug('Starting server. %r' % { 'server_id': self.id, }) self._generate_ovpn_conf() self._enable_ip_forwarding() self._set_iptables_rules() self.clear_output() threading.Thread(target=self._run_thread).start() started = False for message in cache_db.subscribe(self.get_cache_key(), SUB_RESPONSE_TIMEOUT): if message == 'started': started = True break elif message == 'stopped': raise ServerStartError('Server failed to start', { 'server_id': self.id, }) if not started: raise ServerStartError('Server thread failed to return ' + \ 'start event', { 'server_id': self.id, }) if not silent: Event(type=SERVERS_UPDATED) LogEntry(message='Started server "%s".' % self.name) finally: cache_db.lock_release(self.get_cache_key('op_lock'))
def start(self): if self.status: return logger.debug('Starting server. %r' % { 'server_id': self.id, }) self._generate_ovpn_conf() self._enable_ip_forwarding() self._set_iptables_rules() threading.Thread(target=self._run_thread).start() started = False for message in cache_db.subscribe(self.get_cache_key(), SUB_RESPONSE_TIMEOUT): if message == 'started': started = True break elif message == 'stopped': raise ValueError('Server failed to start') if not started: raise ValueError('Server thread failed to return start event.')
def stop(self): cache_db.lock_acquire(self.get_cache_key('op_lock')) try: if not self.status: return logger.debug('Stopping server. %r' % { 'server_id': self.id, }) stopped = False self.publish('stop') for message in cache_db.subscribe(self.get_cache_key(), SUB_RESPONSE_TIMEOUT): if message == 'stopped': stopped = True break if not stopped: raise ServerStopError('Server thread failed to return ' + \ 'stop event', { 'server_id': self.id, }) finally: cache_db.lock_release(self.get_cache_key('op_lock'))