def run(self): """ Starts the Tornado web server and ZeroMQ server. """ router = self._create_zmq_router() # Add our JSON-RPC Websocket handler to Tornado self.handlers.extend([(r"/", JSONRPCWebSocket, dict(zmq_router=router))]) if hasattr(sys, "frozen"): templates_dir = "templates" else: templates_dir = pkg_resources.resource_filename("gns3server", "templates") tornado_app = tornado.web.Application(self.handlers, template_path=templates_dir, debug=True) # FIXME: debug mode! try: print("Starting server on {}:{} (Tornado v{}, PyZMQ v{}, ZMQ v{})".format(self._host, self._port, tornado.version, zmq.__version__, zmq.zmq_version())) kwargs = {"address": self._host} if parse_version(tornado.version) >= parse_version("3.1"): kwargs["max_buffer_size"] = 524288000 # 500 MB file upload limit tornado_app.listen(self._port, **kwargs) except OSError as e: if e.errno == errno.EADDRINUSE: # socket already in use logging.critical("socket in use for {}:{}".format(self._host, self._port)) self._cleanup(graceful=False) ioloop = tornado.ioloop.IOLoop.instance() self._stream = zmqstream.ZMQStream(router, ioloop) self._stream.on_recv_stream(JSONRPCWebSocket.dispatch_message) tornado.autoreload.add_reload_hook(self._reload_callback) def signal_handler(signum=None, frame=None): try: log.warning("Server got signal {}, exiting...".format(signum)) self._cleanup(signum) except RuntimeError: # to ignore logging exception: RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'> pass signals = [signal.SIGTERM, signal.SIGINT] if not sys.platform.startswith("win"): signals.extend([signal.SIGHUP, signal.SIGQUIT]) else: signals.extend([signal.SIGBREAK]) for sig in signals: signal.signal(sig, signal_handler) try: ioloop.start() except (KeyboardInterrupt, SystemExit): print("\nExiting...") self._cleanup()
def main(argv=None): # IGNORE:C0111 '''Command line options.''' if argv is None: argv = sys.argv else: sys.argv.extend(argv) program_name = os.path.basename(sys.argv[0]) try: desc = "Web server for ar lab" parser = ArgumentParser(description="hej", formatter_class=RawDescriptionHelpFormatter) parser.add_argument("-v", "--verbose", dest="verbose", action="count", help="set verbosity level [default: %(default)s]") parser.add_argument('--external-ip', default="127.0.1.1", nargs='?', help='external server ip') # Process arguments args = parser.parse_args() verbose = args.verbose if verbose > 0: print("Verbose mode on") application = DmxUiApp(external_ip=args.external_ip) application.listen(10001) print('starting on port 10001') ioloop.start() return 0 except KeyboardInterrupt: ### handle keyboard interrupt ### return 0 except Exception as e: if DEBUG: raise(e) indent = len(program_name) * " " sys.stderr.write(program_name + ": " + repr(e) + "\n") sys.stderr.write(indent + " for help use --help") return 2
(r'{}/(.*)'.format(user_settings.get('server', 'media_url')), tornado.web.StaticFileHandler, {'path': MEDIA_PATH})) application = UrlistApplication(handlers, **settings) def _clean_shutdown(signum, frame): import sys signame, = [x for x in dir(signal) if getattr(signal, x) == 15 and x.startswith('SIG')] logging.info('APISRV::SHUTDOWN --- {}'.format(signame)) dispatcher.close() sys.exit(0) if __name__ == '__main__': import signal signal.signal(signal.SIGTERM, _clean_shutdown) signal.signal(signal.SIGINT, _clean_shutdown) application.listen(PORT, no_keep_alive=True) logging.info("APISRV::LISTENING --- {}".format(PORT)) ioloop = ioloop.IOLoop.instance() ioloop.start()
application = UrlistApplication(handlers, **settings) def _clean_shutdown(signum, frame): import sys signame, = [ x for x in dir(signal) if getattr(signal, x) == 15 and x.startswith('SIG') ] logging.info('APISRV::SHUTDOWN --- {}'.format(signame)) dispatcher.close() sys.exit(0) if __name__ == '__main__': import signal signal.signal(signal.SIGTERM, _clean_shutdown) signal.signal(signal.SIGINT, _clean_shutdown) application.listen(PORT, no_keep_alive=True) logging.info("APISRV::LISTENING --- {}".format(PORT)) ioloop = ioloop.IOLoop.instance() ioloop.start()
def run(self): """ Starts the Tornado web server and ZeroMQ server. """ settings = { "debug":True, "cookie_secret": base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes), "login_url": "/login", } ssl_options = {} try: cloud_config = Config.instance().get_section_config("CLOUD_SERVER") cloud_settings = { "required_user" : cloud_config['WEB_USERNAME'], "required_pass" : cloud_config['WEB_PASSWORD'], } settings.update(cloud_settings) if cloud_config["SSL_ENABLED"] == "yes": ssl_options = { "certfile" : cloud_config["SSL_CRT"], "keyfile" : cloud_config["SSL_KEY"], } log.info("Certs found - starting in SSL mode") except KeyError: log.info("Missing cloud.conf - disabling HTTP auth and SSL") router = self._create_zmq_router() # Add our JSON-RPC Websocket handler to Tornado self.handlers.extend([(r"/", JSONRPCWebSocket, dict(zmq_router=router))]) if hasattr(sys, "frozen"): templates_dir = "templates" else: templates_dir = pkg_resources.resource_filename("gns3server", "templates") tornado_app = tornado.web.Application(self.handlers, template_path=templates_dir, **settings) # FIXME: debug mode! try: user_log = logging.getLogger('user_facing') user_log.info("Starting server on {}:{} (Tornado v{}, PyZMQ v{}, ZMQ v{})".format( self._host, self._port, tornado.version, zmq.__version__, zmq.zmq_version())) kwargs = {"address": self._host} if ssl_options: kwargs["ssl_options"] = ssl_options if parse_version(tornado.version) >= parse_version("3.1"): kwargs["max_buffer_size"] = 524288000 # 500 MB file upload limit tornado_app.listen(self._port, **kwargs) except OSError as e: if e.errno == errno.EADDRINUSE: # socket already in use logging.critical("socket in use for {}:{}".format(self._host, self._port)) self._cleanup(graceful=False) ioloop = tornado.ioloop.IOLoop.instance() self._stream = zmqstream.ZMQStream(router, ioloop) self._stream.on_recv_stream(JSONRPCWebSocket.dispatch_message) tornado.autoreload.add_reload_hook(self._reload_callback) def signal_handler(signum=None, frame=None): try: log.warning("Server got signal {}, exiting...".format(signum)) self._cleanup(signum) except RuntimeError: # to ignore logging exception: RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'> pass signals = [signal.SIGTERM, signal.SIGINT] if not sys.platform.startswith("win"): signals.extend([signal.SIGHUP, signal.SIGQUIT]) else: signals.extend([signal.SIGBREAK]) for sig in signals: signal.signal(sig, signal_handler) try: ioloop.start() except (KeyboardInterrupt, SystemExit): log.info("\nExiting...") self._cleanup()
def run(self): """ Starts the Tornado web server and ZeroMQ server. """ settings = { "debug": True, "cookie_secret": base64.b64encode(uuid.uuid4().bytes + uuid.uuid4().bytes), "login_url": "/login", } ssl_options = {} try: cloud_config = Config.instance().get_section_config("CLOUD_SERVER") cloud_settings = { "required_user": cloud_config['WEB_USERNAME'], "required_pass": cloud_config['WEB_PASSWORD'], } settings.update(cloud_settings) if cloud_config["SSL_ENABLED"] == "yes": ssl_options = { "certfile": cloud_config["SSL_CRT"], "keyfile": cloud_config["SSL_KEY"], } log.info("Certs found - starting in SSL mode") except KeyError: log.info("Missing cloud.conf - disabling HTTP auth and SSL") router = self._create_zmq_router() # Add our JSON-RPC Websocket handler to Tornado self.handlers.extend([(r"/", JSONRPCWebSocket, dict(zmq_router=router)) ]) if hasattr(sys, "frozen"): templates_dir = "templates" else: templates_dir = pkg_resources.resource_filename( "gns3server", "templates") tornado_app = tornado.web.Application(self.handlers, template_path=templates_dir, **settings) # FIXME: debug mode! try: print("Starting server on {}:{} (Tornado v{}, PyZMQ v{}, ZMQ v{})". format(self._host, self._port, tornado.version, zmq.__version__, zmq.zmq_version())) kwargs = {"address": self._host} if ssl_options: kwargs["ssl_options"] = ssl_options if parse_version(tornado.version) >= parse_version("3.1"): kwargs[ "max_buffer_size"] = 524288000 # 500 MB file upload limit tornado_app.listen(self._port, **kwargs) except OSError as e: if e.errno == errno.EADDRINUSE: # socket already in use logging.critical("socket in use for {}:{}".format( self._host, self._port)) self._cleanup(graceful=False) ioloop = tornado.ioloop.IOLoop.instance() self._stream = zmqstream.ZMQStream(router, ioloop) self._stream.on_recv_stream(JSONRPCWebSocket.dispatch_message) tornado.autoreload.add_reload_hook(self._reload_callback) def signal_handler(signum=None, frame=None): try: log.warning("Server got signal {}, exiting...".format(signum)) self._cleanup(signum) except RuntimeError: # to ignore logging exception: RuntimeError: reentrant call inside <_io.BufferedWriter name='<stderr>'> pass signals = [signal.SIGTERM, signal.SIGINT] if not sys.platform.startswith("win"): signals.extend([signal.SIGHUP, signal.SIGQUIT]) else: signals.extend([signal.SIGBREAK]) for sig in signals: signal.signal(sig, signal_handler) try: ioloop.start() except (KeyboardInterrupt, SystemExit): print("\nExiting...") self._cleanup()