def main(): _pool = Pool() service = Service() server = Server(listener=ADDR, handle=service.handle, spawn=_pool.spawn) app = Application(server) message.sub(Server.NEW_CONNECTION, service.new_connection) message.sub(Server.LOST_CONNECTION, service.lost_connection) print '=' * 50 print '=', ' '*15, 'Server Started', ' '*15, '=' print '=' * 50 app.run()
def main(): port = Setting.getGatewayPort() if not port: port = Cfg.CFG_GATEWAYSERV_PORT _pool = gevent.pool.Pool() service = Service() server = Server(('0.0.0.0', int(port)), handle=service.handle, spawn=_pool.spawn) #=========================================================== import signal logger = Gcore.getLogger('server', 'server') def close_server(): logger.warning('I got a signal.SIGUSR1 going to stop battle server') server.stop(180) def reload_server(): Gcore.reload() logger.warning('I got a signal.SIGUSR2, battle server Gcore reload()') def hook_signal(): '''捕获信号''' if os.name == 'nt': return #信号10-关服 gevent.signal(signal.SIGUSR1, close_server) #信号12-重载 gevent.signal(signal.SIGUSR2, reload_server) hook_signal() #===================================================================== message.sub(Server.NEW_CONNECTION, service.new_connection) message.sub(Server.LOST_CONNECTION, service.lost_connection) app = Application(server) print '=' * 50 print '=', ' ' * 15, 'Server Started', ' ' * 15, '=' print '=' * 50 app.run() if pid_file: with open(pid_file, 'wb') as fd: fd.write('0')
def main(): port = Setting.getGatewayPort() if not port: port = Cfg.CFG_GATEWAYSERV_PORT _pool = gevent.pool.Pool() service = Service() server = Server(('0.0.0.0', int(port)), handle=service.handle, spawn=_pool.spawn) message.sub(Server.NEW_CONNECTION, service.new_connection) message.sub(Server.LOST_CONNECTION, service.lost_connection) app = Application(server) print '=' * 50 print '=', ' '*15, 'Server Started', ' '*15, '=' print '=' * 50 app.run()
def main(): port = Setting.getGatewayPort() if not port: port = Cfg.CFG_BATTLESERV_PORT _pool = gevent.pool.Pool() service = Service() server = Server(('0.0.0.0', int(port) ), handle=service.handle, spawn=_pool.spawn) #=========================================================== import signal logger = Gcore.getLogger('server', 'server') def close_server(): logger.warning('I got a signal.SIGUSR1 going to stop server') server.stop(180) def reload_server(): Gcore.reload() logger.warning('I got a signal.SIGUSR2, Gcore reload()') def hook_signal(): '''捕获信号''' if os.name == 'nt': return #信号10-关服 gevent.signal(signal.SIGUSR1, close_server) #信号12-重载 gevent.signal(signal.SIGUSR2, reload_server) hook_signal() #===================================================================== message.sub(Server.NEW_CONNECTION, service.new_connection) message.sub(Server.LOST_CONNECTION, service.lost_connection) app = Application(server) print '=' * 50 print '=', ' '*15, 'Server Started', ' '*15, '=' print '=' * 50 app.run() if pid_file: with open(pid_file, 'wb') as fd: fd.write('0')
def main(): _pool = gevent.pool.Pool() service = Service() server = Server(('0.0.0.0', int(port)), handle=service.handle, spawn=_pool.spawn) def close_server(): #server.kill() server.stop(180) print 'server.stop' def start_server(): if server.started: print '服务器已经启动' return server.start() print 'server.start' def hook_signal(): '''捕获信号''' if os.name == 'nt': return #信号10-开服 gevent.signal(signal.SIGUSR1, start_server) #信号12-关服 gevent.signal(signal.SIGUSR2, close_server) message.sub(Server.NEW_CONNECTION, service.new_connection) message.sub(Server.LOST_CONNECTION, service.lost_connection) app = Application(server) hook_signal() print '=' * 50 print '=', ' '*15, 'Server Started', ' '*15, '=' print '=' * 50 app.run()
def main(): port = Setting.getGatewayPort() if not port: port = Cfg.CFG_GATEWAYSERV_PORT _pool = gevent.pool.Pool() service = Service() server = Server(('0.0.0.0', int(8099)), handle=service.handle, spawn=_pool.spawn) #=========================================================== import signal #对linux一些信号进行捕获 def hook_signal(): if os.name != "nt": signal.signal(signal.SIGBUS, signal_handle) signal.signal(signal.SIGTERM, signal_handle) signal.signal(signal.SIGUSR1, signal_handle) signal.signal(signal.SIGUSR2, signal_handle) signal.signal(signal.SIGABRT, signal_handle) #屏蔽与终端控制有关的信号 signal.signal(signal.SIGTTOU, signal.SIG_IGN) signal.signal(signal.SIGTTIN, signal.SIG_IGN) signal.signal(signal.SIGTSTP, signal.SIG_IGN) signal.signal(signal.SIGHUP, signal.SIG_IGN) #linux信号处理函数 def signal_handle(sign_num, frame): import signal logger = Gcore.getLogger('system', 'server') if sign_num == signal.SIGBUS: server.stop(180) logger.warning('I got a signal.SIGBUS server stop') sys.exit(-1) elif sign_num == signal.SIGTERM: server.stop(180) logger.warning('I got a signal.SIGTERM server stop') elif sign_num == signal.SIGHUP: logger.warning('I got a signal.SIGHUP pass') pass elif sign_num == signal.SIGUSR1: #用户发送停止服务的指令 10 logger.warning('I got a signal.SIGUSR1 going to stop server') server.stop(180) elif sign_num == signal.SIGUSR2: # 12 Gcore.reload() logger.warning('I got a signal.SIGUSR2, Gcore reload()') hook_signal() #===================================================================== message.sub(Server.NEW_CONNECTION, service.new_connection) message.sub(Server.LOST_CONNECTION, service.lost_connection) app = Application(server) print '=' * 50 print '=', ' ' * 15, 'Server Started', ' ' * 15, '=' print '=' * 50 app.run() Gcore.log.warning('I got a signal.SIGUSR1 have stoped server') if pid_file: with open(pid_file, 'wb') as fd: fd.write('0')
def main(): port = Setting.getGatewayPort() if not port: port = Cfg.CFG_GATEWAYSERV_PORT _pool = gevent.pool.Pool() service = Service() server = Server(('0.0.0.0', int(port)), handle=service.handle, spawn=_pool.spawn) #=========================================================== import signal ''' #对linux一些信号进行捕获 def hook_signal(): if os.name != "nt": gevent.signal(signal.SIGBUS,signal_handle) gevent.signal(signal.SIGTERM, signal_handle) gevent.signal(signal.SIGUSR1, signal_handle) gevent.signal(signal.SIGUSR2, signal_handle) gevent.signal(signal.SIGABRT, signal_handle) #屏蔽与终端控制有关的信号 gevent.signal(signal.SIGTTOU,signal.SIG_IGN) gevent.signal(signal.SIGTTIN,signal.SIG_IGN) gevent.signal(signal.SIGTSTP,signal.SIG_IGN) gevent.signal(signal.SIGHUP ,signal.SIG_IGN) #linux信号处理函数 def signal_handle(sign_num, frame): import signal logger = Gcore.getLogger('system', 'server') if sign_num == signal.SIGBUS: server.stop(180) logger.warning('I got a signal.SIGBUS server stop') sys.exit(-1) elif sign_num == signal.SIGTERM: server.stop(180) logger.warning('I got a signal.SIGTERM server stop') elif sign_num == signal.SIGHUP: logger.warning('I got a signal.SIGHUP pass') pass elif sign_num == signal.SIGUSR1: #用户发送停止服务的指令 10 logger.warning('I got a signal.SIGUSR1 going to stop server') server.stop(180) elif sign_num == signal.SIGUSR2: # 12 Gcore.reload() logger.warning('I got a signal.SIGUSR2, Gcore reload()') ''' def close_server(): logger.warning('I got a signal.SIGUSR1 going to stop server') server.stop(180) def reload_server(): Gcore.reload() logger.warning('I got a signal.SIGUSR2, Gcore reload()') def hook_signal(): '''捕获信号''' if os.name == 'nt': return #信号10-关服 gevent.signal(signal.SIGUSR1, close_server) #信号12-重载 gevent.signal(signal.SIGUSR2, reload_server) hook_signal() #===================================================================== message.sub(Server.NEW_CONNECTION, service.new_connection) message.sub(Server.LOST_CONNECTION, service.lost_connection) app = Application(server) print '=' * 50 print '=', ' '*15, 'Server Started', ' '*15, '=' print '=' * 50 app.run() Gcore.log.warning('I got a signal.SIGUSR1 have stoped server') if pid_file: with open(pid_file, 'wb') as fd: fd.write('0')
def main(): port = Setting.getGatewayPort() if not port: port = Cfg.CFG_GATEWAYSERV_PORT _pool = gevent.pool.Pool() service = Service() server = Server(("0.0.0.0", int(8099)), handle=service.handle, spawn=_pool.spawn) # =========================================================== import signal # 对linux一些信号进行捕获 def hook_signal(): if os.name != "nt": signal.signal(signal.SIGBUS, signal_handle) signal.signal(signal.SIGTERM, signal_handle) signal.signal(signal.SIGUSR1, signal_handle) signal.signal(signal.SIGUSR2, signal_handle) signal.signal(signal.SIGABRT, signal_handle) # 屏蔽与终端控制有关的信号 signal.signal(signal.SIGTTOU, signal.SIG_IGN) signal.signal(signal.SIGTTIN, signal.SIG_IGN) signal.signal(signal.SIGTSTP, signal.SIG_IGN) signal.signal(signal.SIGHUP, signal.SIG_IGN) # linux信号处理函数 def signal_handle(sign_num, frame): import signal logger = Gcore.getLogger("system", "server") if sign_num == signal.SIGBUS: server.stop(180) logger.warning("I got a signal.SIGBUS server stop") sys.exit(-1) elif sign_num == signal.SIGTERM: server.stop(180) logger.warning("I got a signal.SIGTERM server stop") elif sign_num == signal.SIGHUP: logger.warning("I got a signal.SIGHUP pass") pass elif sign_num == signal.SIGUSR1: # 用户发送停止服务的指令 10 logger.warning("I got a signal.SIGUSR1 going to stop server") server.stop(180) elif sign_num == signal.SIGUSR2: # 12 Gcore.reload() logger.warning("I got a signal.SIGUSR2, Gcore reload()") hook_signal() # ===================================================================== message.sub(Server.NEW_CONNECTION, service.new_connection) message.sub(Server.LOST_CONNECTION, service.lost_connection) app = Application(server) print "=" * 50 print "=", " " * 15, "Server Started", " " * 15, "=" print "=" * 50 app.run() Gcore.log.warning("I got a signal.SIGUSR1 have stoped server") if pid_file: with open(pid_file, "wb") as fd: fd.write("0")