def run_worker_process(self): setup_logger(self.quiet, log) if self.registry_type == "UDP": if self.registry_host is None: self.registry_host = "255.255.255.255" self.registrar = UDPRegistryClient(ip=self.registry_host, port=self.registry_port) else: if self.registry_host is None: raise ValueError( "With TCP registry, you must specify --registry-host") self.registrar = TCPRegistryClient(ip=self.registry_host, port=self.registry_port) t = ThreadPoolServer(ServiceEnvelope.SERVICE_CLASS, hostname=self.host, port=self.port, reuse_addr=True, ipv6=self.ipv6, registrar=self.registrar, auto_register=self.auto_register, nbThreads=self.max_client_count, requestBatchSize=self.max_requests_per_client, protocol_config={ 'exposed_prefix': '', 'log_exceptions': True }) t.start()
def main(self): if self.registry_type == "UDP": if self.registry_host is None: self.registry_host = "255.255.255.255" self.registrar = UDPRegistryClient(ip = self.registry_host, port = self.registry_port) else: if self.registry_host is None: raise ValueError("With TCP registry, you must specify --registry-host") self.registrar = TCPRegistryClient(ip = self.registry_host, port = self.registry_port) if self.ssl_keyfile: self.authenticator = SSLAuthenticator(self.ssl_keyfile, self.ssl_certfile, self.ssl_cafile) default_port = DEFAULT_SERVER_SSL_PORT else: self.authenticator = None default_port = DEFAULT_SERVER_PORT if self.port is None: self.port = default_port setup_logger(self.quiet, self.logfile) if self.mode == "threaded": factory = ThreadedServer elif self.mode == "forking": factory = ForkingServer elif self.mode == "stdio": self._serve_stdio() return t = factory(SlaveService, hostname = self.host, port = self.port, reuse_addr = True, ipv6 = self.ipv6, authenticator = self.authenticator, registrar = self.registrar, auto_register = self.auto_register) t.start()
def start(): global server conf = ConfigParser() conf.read([ os.path.join(cur_dir, 'rpycd.conf'), os.path.join(bin_dir, 'rpycd.conf'), # later files trump earlier ones ]) mode = conf.get("rpycd", "mode").lower() if mode == "threaded": factory = ThreadedServer elif mode == "forking": factory = ForkingServer else: raise ValueError(f"Invalid mode {mode!r}") quiet = conf.getboolean("rpycd", "quiet") logfile = os.path.join(cur_dir, conf.get("rpycd", "logfile")) setup_logger(quiet, logfile) server = factory(SlaveService, hostname=conf.get("rpycd", "host"), port=conf.getint("rpycd", "port"), reuse_addr=True) server.start() server.serve_all()
def __init__(self, host="", port=None, forking=False, registry_host=None, ipv6=True, ssl_keyfile=None, ssl_certfile=None, ssl_cafile=None): self._host = host self._port = port self._ipv6 = ipv6 self._registry_host = registry_host self._ssl_keyfile = ssl_keyfile self._ssl_certfile = ssl_certfile self._ssl_cafile = ssl_cafile if self._registry_host is None: self._registry_host = '255.255.255.255' self._registry_port = REGISTRY_PORT self._registrar = UDPRegistryClient(ip = self._registry_host, port = self._registry_port) if self._ssl_keyfile: self._authenticator = SSLAuthenticator(self._ssl_keyfile, self._ssl_certfile, self._ssl_cafile) default_port = DEFAULT_SERVER_SSL_PORT else: self._authenticator = None default_port = DEFAULT_SERVER_PORT if self._port is None: self._port = default_port setup_logger(False, None) factory = ForkingServer if forking else ThreadedServer self._t = factory(SlaveService, hostname = self._host, port = self._port, reuse_addr = True, ipv6 = self._ipv6, authenticator = self._authenticator, registrar = self._registrar, auto_register = False)
def main(self): if not self.host: self.host = "::1" if self.ipv6 else "127.0.0.1" if self.registry_type == "UDP": if self.registry_host is None: self.registry_host = "255.255.255.255" self.registrar = UDPRegistryClient(ip = self.registry_host, port = self.registry_port) else: if self.registry_host is None: raise ValueError("With TCP registry, you must specify --registry-host") self.registrar = TCPRegistryClient(ip = self.registry_host, port = self.registry_port) if self.ssl_keyfile: self.authenticator = SSLAuthenticator(self.ssl_keyfile, self.ssl_certfile, self.ssl_cafile) default_port = DEFAULT_SERVER_SSL_PORT else: self.authenticator = None default_port = DEFAULT_SERVER_PORT if self.port is None: self.port = default_port setup_logger(self.quiet, self.logfile) if self.mode == "threaded": self._serve_mode(ThreadedServer) elif self.mode == "forking": self._serve_mode(ForkingServer) elif self.mode == "oneshot": self._serve_oneshot() elif self.mode == "stdio": self._serve_stdio()
def main(self): if not self.host: self.host = "::1" if self.ipv6 else "127.0.0.1" if self.registry_type == "UDP": if self.registry_host is None: self.registry_host = "255.255.255.255" self.registrar = UDPRegistryClient(ip=self.registry_host, port=self.registry_port) else: if self.registry_host is None: raise ValueError("With TCP registry, you must specify --registry-host") self.registrar = TCPRegistryClient(ip=self.registry_host, port=self.registry_port) if self.ssl_keyfile: self.authenticator = SSLAuthenticator(self.ssl_keyfile, self.ssl_certfile, self.ssl_cafile) default_port = DEFAULT_SERVER_SSL_PORT else: self.authenticator = None default_port = DEFAULT_SERVER_PORT if self.port is None: self.port = default_port setup_logger(self.quiet, self.logfile) if self.mode == "threaded": self._serve_mode(ThreadedServer) elif self.mode == "forking": self._serve_mode(ForkingServer) elif self.mode == "oneshot": self._serve_oneshot() elif self.mode == "stdio": self._serve_stdio()
def main(self): if self.mode == "UDP": server = UDPRegistryServer(host='::' if self.ipv6 else '0.0.0.0', port=self.port, pruning_timeout=self.pruning_timeout) elif self.mode == "TCP": server = TCPRegistryServer(port=self.port, pruning_timeout=self.pruning_timeout) setup_logger(self.quiet, self.logfile) server.start()
def main(self): if self.mode == "UDP": server = UDPRegistry(host = '::' if self.ipv6 else '0.0.0.0', port = self.port, pruning_timeout = self.pruning_timeout) elif self.mode == "TCP": server = TCPRegistryServer(port = self.port, pruning_timeout = self.pruning_timeout) setup_logger(self.quiet, self.logfile) server.start()
def main(self): if self.mode == "UDP": server = UDPRegistryServer(host=self.host, port=self.port, pruning_timeout=self.timeout) elif self.mode == "TCP": server = TCPRegistryServer( port=self.port, pruning_timeout=self.timeout) setup_logger(self.quiet, self.logfile) print >> sys.stderr, "Starting registry on port %s..." % self.port server.start()
def main(self): if self.registry_type == "UDP": if self.registry_host is None: self.registry_host = "255.255.255.255" self.registrar = UDPRegistryClient( ip=self.registry_host, port=self.registry_port) else: if self.registry_host is None: raise ValueError( "With TCP registry, you must specify --registry-host") self.registrar = TCPRegistryClient( ip=self.registry_host, port=self.registry_port) if self.ssl_keyfile: self.authenticator = SSLAuthenticator( self.ssl_keyfile, self.ssl_certfile, self.ssl_cafile) default_port = DEFAULT_SERVER_SSL_PORT else: self.authenticator = None default_port = DEFAULT_SERVER_PORT if self.port is None: self.port = default_port setup_logger(self.quiet, self.logfile) sys.stdout.write( BANNER + " starting at %s %s\n" % (self.host, self.port)) sys.stdout.flush() done_event = threading.Event() srv = WeirdServer( SlaveService, done_event, hostname=self.host, port=self.port, reuse_addr=True, ipv6=self.ipv6, authenticator=self.authenticator, registrar=self.registrar, auto_register=self.auto_register) t = threading.Thread(target=self._serve, args=[srv]) t.start() # wait for 2 connections done_event.wait() IPython.embed( banner1=BANNER + " client connected\n", banner2="", # "tip: call serve_all() on the client to have a full working shell here.", exit_msg=BANNER + " shell closed.\nexiting...\n" ) os.kill(srv.proc, signal.SIGKILL) os._exit(0)
def serve_forking(options): setup_logger(options) t = ForkingServer(SlaveService, hostname = options.host, port = options.port, reuse_addr = True, ipv6 = options.ipv6, authenticator = options.authenticator, registrar = options.registrar, auto_register = options.auto_register) t.logger.quiet = options.quiet if options.logfile: t.logger.console = open(options.logfile, "w") t.start()
def main(self): if self.mode == "UDP": server = UDPRegistryServer(host=self.host, port=self.port, pruning_timeout=self.timeout) elif self.mode == "TCP": server = TCPRegistryServer(port=self.port, pruning_timeout=self.timeout) setup_logger(self.quiet, self.logfile) print >> sys.stderr, "Starting registry on port %s..." % self.port server.start()
def serve_forking(options): setup_logger(options) t = ForkingServer(SlaveService, hostname=options.host, port=options.port, reuse_addr=True, authenticator=options.authenticator, registrar=options.registrar, auto_register=options.auto_register) t.logger.quiet = options.quiet if options.logfile: t.logger.console = open(options.logfile, "w") t.start()
def serve_threaded(options): setup_logger(options) t = ThreadedServer( SlaveService, hostname=options.host, port=options.port, reuse_addr=True, authenticator=options.authenticator, registrar=options.registrar, auto_register=options.auto_register, ) t.logger.quiet = options.quiet if options.logfile: t.logger.console = open(options.logfile, "w") t.start()
def query(service_name, host=REGISTRY_DEFAULT_HOST, port=REGISTRY_DEFAULT_PORT, timeout=DEFAULT_PRUNING_TIMEOUT, logger=None, mode="UDP"): if logger: setup_logger(False, logger) if mode not in ["UDP", "TCP"]: raise ValueError("Unknown registry mode '%s', expected %s" % (mode, str(["UDP", "TCP"]))) if mode == "UDP": client = UDPRegistryClient else: client = TCPRegistryClient registrar = client(host, port, timeout) return registrar.discover(service_name)
def main(): options, args = parser.parse_args() if args: raise ValueError("does not take positional arguments: %r" % (args,)) if options.port < 1 or options.port > 65535: raise ValueError("invalid TCP/UDP port %r" % (options.port,)) if options.mode.lower() == "udp": server = UDPRegistryServer(port = options.port, pruning_timeout = options.pruning_timeout) elif options.mode.lower() == "tcp": server = TCPRegistryServer(port = options.port, pruning_timeout = options.pruning_timeout) else: raise ValueError("invalid mode %r" % (options.mode,)) setup_logger(options) server.start()
def start(): global server conf = ConfigParser() conf.read('rpycd.conf') mode = conf.get("rpycd", "mode").lower() if mode == "threaded": factory = ThreadedServer elif mode == "forking": factory = ForkingServer else: raise ValueError("Invalid mode %r" % (mode,)) setup_logger(conf.getboolean("rpycd", "quiet"), conf.get("rpycd", "logfile")) server = factory(SlaveService, hostname = conf.get("rpycd", "host"), port = conf.getint("rpycd", "port"), reuse_addr = True) server.start()
def main(): options, args = parser.parse_args() if args: raise ValueError("does not take positional arguments: %r" % (args, )) if options.port < 1 or options.port > 65535: raise ValueError("invalid TCP/UDP port %r" % (options.port, )) if options.mode.lower() == "udp": server = UDPRegistryServer(port=options.port, pruning_timeout=options.pruning_timeout) elif options.mode.lower() == "tcp": server = TCPRegistryServer(port=options.port, pruning_timeout=options.pruning_timeout) else: raise ValueError("invalid mode %r" % (options.mode, )) setup_logger(options) server.start()
def main(self): if self.ssl_keyfile: self.authenticator = SSLAuthenticator(self.ssl_keyfile, self.ssl_certfile, self.ssl_cafile) default_port = DEFAULT_SERVER_SSL_PORT else: self.authenticator = None default_port = DEFAULT_SERVER_PORT if self.port is None: self.port = default_port setup_logger(self.quiet, self.logfile) server = ThreadedServer(BBTestService, hostname=self.host, port=self.port, authenticator=self.authenticator) server.start()
def start_rpc_server( **options ): host = options.get( 'host', '0.0.0.0' ) port = options.get( 'port', _GII_RPC_PORT ) import rpyc from rpyc.core import SlaveService from rpyc.lib import setup_logger setup_logger() import locale encoding = options.get( 'encoding', locale.getpreferredencoding() ) os.environ[ 'GII_RPC_STDIO_ENCODING' ] = encoding try: print( 'starting RPC server', host, port, encoding ) server = rpyc.utils.server.ThreadedServer( SlaveService, port=port, hostname=host, reuse_addr = True ) server.start() except Exception as e: print(e) return False
def start(): global server conf = configparser.ConfigParser() conf.read('rpycd.conf') mode = conf.get("rpycd", "mode").lower() if mode == "threaded": factory = ThreadedServer elif mode == "forking": factory = ForkingServer else: raise ValueError("Invalid mode %r" % (mode, )) setup_logger(conf.getboolean("rpycd", "quiet"), conf.get("rpycd", "logfile")) server = factory(SlaveService, hostname=conf.get("rpycd", "host"), port=conf.getint("rpycd", "port"), reuse_addr=True) server.start()
def main(): options, args = parser.parse_args() server = TCPRegistryServer(port=18811, pruning_timeout=61) setup_logger(options) server.start()
return (dn) @staticmethod def exposed_filemap(): # Function to get the list of files from all the Dnodes filetable = [] for DN in __class__.DN_LIST: # Iterating through the DNodes dcon = rpyc.connect(DN[0],DN[1]) # connect to DNode (host,port) dn = dcon.root.DNode() # Allows calling of exposed remote DNode server functions temptable = filetable filemap = dn.filequery() # Exectutes the 'exposed_filequery()' function in DNode & returns values print (type(filemap), "\n", filemap) # returns a <netref class 'rpyc.core.netref.builtins.list'> object filemap= list(filemap) # Convert to list object filetable = temptable + filemap # Appends the file list to the existing list print (filetable) df = pd.DataFrame(filetable) # Converts the list of dictionaries to dataframe print (df.to_string(index=False)) return (df) if __name__ == "__main__": host = "127.0.0.1" port = input("Enter the server port [Default = 18812]:") # Allows user to enter a port number for Server if port: port = int(port) else: port = 18812 # Sets default value as 18812 if no port number is specified by user t = ThreadedServer(MasterServer, hostname=host, port=port,protocol_config={'allow_public_attrs': True}) """ 'allow_public_attrs' creates the Threaded RPyc server to allow the attributes to be accessible to users i.e. allow normal actions on dict, dataframes """ setup_logger(quiet=False, logfile=None) # Start logging online t.start() # Start the MasterServer
) # need to specify full path+filename to get the filesize as only filename is not recognized mtime = dt.fromtimestamp( os.path.getmtime(os.path.join(dirpath, file)) ) # This returns a datetime object datetime.datetime(YYYY, MM, DD, hh, mm, ss, ms) tempdict['ModTime'] = mtime.strftime( timeformat ) # Formats the mtime to "YYYY-MM-DD hh:mm:ss" which is human readable filelist.append( tempdict) # Appends each file to the filelist print(filelist) return (filelist) if __name__ == "__main__": t2 = ThreadedServer(DNServer, hostname=IP, port=PORT, protocol_config={'allow_public_attrs': True}) # 'allow_public_attrs' is needed to make the rpyc items visible. If this is not specified, it will result in errors # .. since rpyc dicts & lists are not visible as normal dict and list # e.g. while converting an rpyc list of dict (filelist) to dataframe, it returns 'keys' error setup_logger(quiet=False, logfile=None) subprocess.call( "start cmd /K python ftpserver2.py", shell=True ) # this opens the ftpserver2.py file in a new console window (shell=True) so that we can view the FTP logs t2.start() # Start the DNode server """ NOTE: Here we call the ftpserver script separately as including teh FTP script in this file creates collision between the rpyc logging and ftp logging & it was difficult to run both simultaneously USing a new window for FTPserver fixes this issue """
from rpyc.lib import setup_logger import signal def _handle_sighup(myrpcserver, signum, unused): """Closes (terminates) all of its clients. Though keeps server running.""" print("SIGHUP: stopping all clients", sys.stderr) if myrpcserver._closed: return for c in set(myrpcserver.clients): try: c.shutdown(socket.SHUT_RDWR) except Exception: pass c.close() myrpcserver.clients.clear() ThreadedServer._handle_sighup = _handle_sighup setup_logger(False, None) myrpcserver = ThreadedServer(SlaveService, hostname="", port=DEFAULT_SERVER_PORT, reuse_addr=True, ipv6=False) signal.signal(signal.SIGHUP, myrpcserver._handle_sighup) myrpcserver.start()
def start(self): setup_logger(False, None) super(SimRegistry, self).start()
stderr=out, env=new_env) p.wait() returncode = p.returncode data = {} data['sid'] = sid data['nodeip'] = localip if returncode == 0: data['status'] = 0 if returncode != 0: data['status'] = 1 baseurl = "http://" + manserver changenode = httpclient(baseurl + '/api/task/flow/node/status', headers=header, method="POST", data=data) if changenode: out.write("%s 修改节点状态成功\n" % ctime()) else: out.write("%s 修改节点状态失败\n" % ctime()) def exposed_taskresult(self, sid): with open(logdir + "/" + sid + ".log", "r") as log: return log.read() if __name__ == '__main__': setup_logger(quiet=True, logfile=logdir + "/" + logfile) rpycServer = ThreadedServer(RPyCService, port=port, auto_register=False) rpycServer.start()