def run(self): logging.debug("Server: starting server") util.initialize_rpc_threadpool() self.server = grpc.server(futures.ThreadPoolExecutor( max_workers=prefs.get_server_pool_max_threads()), options=None) warp_pb2_grpc.add_WarpServicer_to_server(self, self.server) pair = auth.get_singleton().get_server_creds() server_credentials = grpc.ssl_server_credentials((pair, )) self.server.add_secure_port('[::]:%d' % prefs.get_port(), server_credentials) self.server.start() auth.get_singleton().restart_cert_server() self.start_zeroconf() self.server_thread_keepalive.clear() self.idle_emit("server-started") # **** RUNNING **** while not self.server_thread_keepalive.is_set(): self.server_thread_keepalive.wait(10) # **** STOPPING **** logging.debug("Server: stopping server") remote_machines = list(self.remote_machines.values()) for remote in remote_machines: self.idle_emit("remote-machine-removed", remote) logging.debug( "Server: Closing connection to remote machine %s (%s:%d)" % (remote.display_hostname, remote.ip_address, remote.port)) remote.shutdown() remote_machines = None logging.debug("Server: stopping authentication server") auth.get_singleton().shutdown() logging.debug("Server: stopping discovery and advertisement") self.zeroconf.close() logging.debug("Server: terminating server") self.server.stop(grace=2).wait() self.idle_emit("shutdown-complete") self.server = None util.global_rpc_threadpool.shutdown(wait=True) logging.debug("Server: server stopped")
def run(self): logging.debug("Server: starting server on %s (%s)" % (self.ips, self.iface)) logging.info("Using api version %s" % config.RPC_API_VERSION) logging.info("Our uuid: %s" % auth.get_singleton().get_ident()) self.remote_registrar = remote_registration.Registrar( self.ips, self.port, self.auth_port, self.ips) util.initialize_rpc_threadpool() options = (('grpc.keepalive_time_ms', 10 * 1000), ('grpc.keepalive_timeout_ms', 5 * 1000), ('grpc.keepalive_permit_without_calls', True), ('grpc.http2.max_pings_without_data', 0), ('grpc.http2.min_time_between_pings_ms', 10 * 1000), ('grpc.http2.min_ping_interval_without_data_ms', 5 * 1000)) self.server = grpc.server(futures.ThreadPoolExecutor( max_workers=prefs.get_server_pool_max_threads()), options=options) warp_pb2_grpc.add_WarpServicer_to_server(self, self.server) pair = auth.get_singleton().get_server_creds() server_credentials = grpc.ssl_server_credentials((pair, )) if self.ips.ip4: self.server.add_secure_port('%s:%d' % (self.ips.ip4, self.port), server_credentials) # if self.ips.ip6: # self.server.add_secure_port('%s:%d' % (self.ips.ip6, self.port), # server_credentials) self.server.start() self.start_zeroconf() self.server_thread_keepalive.clear() self.idle_emit("server-started") logging.info("Server: ACTIVE") # **** RUNNING **** while not self.server_thread_keepalive.is_set(): self.server_thread_keepalive.wait(10) # **** STOPPING **** self.remote_registrar.shutdown_registration_servers() self.remote_registrar = None logging.debug("Server: stopping discovery and advertisement") # If the network is down, this will probably print an exception - it's ok, # zeroconf catches it. self.zeroconf.close() remote_machines = list(self.remote_machines.values()) for remote in remote_machines: self.idle_emit("remote-machine-removed", remote) logging.debug( "Server: Closing connection to remote machine %s (%s:%d)" % (remote.display_hostname, remote.ips, remote.port)) remote.shutdown() remote_machines = None logging.debug("Server: terminating server") self.server.stop(grace=2).wait() self.idle_emit("shutdown-complete") self.server = None util.global_rpc_threadpool.shutdown(wait=True) logging.debug("Server: server stopped")