예제 #1
0
def main():
    parse_command_line()
    settings = dict(
        pipeline_file=options.pipeline
    )
    app = remotecontrol.app.Application(settings)
    options.logging = str('DEBUG')
    enable_pretty_logging(options)
    app_log.setLevel(logging.DEBUG)

    server = HTTPServer(app)
    server.listen(options.port, options.host)
    app_log.info("Version: %s from: %s" % (remotecontrol.VERSION, remotecontrol.VERSION_DATE))
    app_log.info("Listen on http://%s:%d/" % (
        options.host if options.host != "" else "localhost",
        options.port)
    )
    # app.processor.start()
    second_tick = None
    try:
        tornado.autoreload.add_reload_hook(app.manager.stop)
        second_tick = tornado.ioloop.PeriodicCallback(lambda: app.second_tick(), 1000)
        second_tick.start()
        tornado.ioloop.IOLoop.instance().start()
    except KeyboardInterrupt:
        second_tick.stop()
        app_log.info("stop second tick")
        app.manager.stop()
        tornado.ioloop.IOLoop.instance().stop()
    app_log.debug("Server shutdown.")
예제 #2
0
    def init_logger(cls, port):
        formatter = LogFormatter(fmt=cls.__fmt.format(port=port),
                                 datefmt="",
                                 color=False)

        access_log_handler = ConcurrentRotatingFileHandler(
            filename=os.path.join(ServerConfig["log_dir"], "access.log"))
        access_log_handler.setFormatter(formatter)
        access_log.addHandler(access_log_handler)

        server_log_handler = ConcurrentRotatingFileHandler(
            filename=os.path.join(ServerConfig['log_dir'], 'server.log'),
            maxBytes=128 * 1024 * 1024,
            backupCount=5,
            encoding='utf8')
        server_log_handler.setFormatter(formatter)
        gen_log.addHandler(server_log_handler)
        app_log.addHandler(server_log_handler)

        access_log.setLevel(logging.INFO)
        gen_log.setLevel(getattr(logging, ServerConfig['log_level'].upper()))
        app_log.setLevel(getattr(logging, ServerConfig['log_level'].upper()))

        access_log.propagate = app_log.propagate = gen_log.propagate = False
        return
예제 #3
0
def main():
    """ entry """
    try:
        conf = __import__('conf')
    except ImportError as e:
        app_log.critical("Unable to load site config. ({})".format(e))
        raise SystemExit()
    parse_command_line()

    if options.debug:
        app_log.setLevel(logging.DEBUG)

    if not options.debug:
        fork_processes(None)
    options.port += task_id() or 0

    if not os.path.isdir(conf.app_path):
        app_log.critical("{p} isn't accessible, maybe "
                         "create it?".format(p=conf.app_path))
        raise SystemExit()
    app_log.debug("Starting {name} on port {port}".format(name=conf.name,
                                                          port=options.port))
    # initialize the application
    tornado.httpserver.HTTPServer(Application(options,
                                              conf)).listen(options.port,
                                                            '0.0.0.0')
    ioloop = tornado.ioloop.IOLoop.instance()
    if options.debug:
        tornado.autoreload.start(ioloop)
    # enter the Tornado IO loop
    ioloop.start()
예제 #4
0
    def server_thread():
        from tornado.log import access_log, app_log, gen_log
        access_log.setLevel(logging.ERROR)
        app_log.setLevel(logging.ERROR)
        gen_log.setLevel(logging.ERROR)

        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        set_ioloop(tornado.ioloop.IOLoop.current())  # to enable bokeh app

        port = 0
        if os.environ.get("PYWEBIO_SCRIPT_MODE_PORT"):
            port = int(os.environ.get("PYWEBIO_SCRIPT_MODE_PORT"))

        server, port = _setup_server(webio_handler=SingleSessionWSHandler,
                                     port=port,
                                     host='localhost')
        tornado.ioloop.IOLoop.current().spawn_callback(
            partial(wait_to_stop_loop, server=server))

        if "PYWEBIO_SCRIPT_MODE_PORT" not in os.environ:
            tornado.ioloop.IOLoop.current().spawn_callback(
                open_webbrowser_on_server_started, 'localhost', port)

        tornado.ioloop.IOLoop.current().start()
        logger.debug('Tornado server exit')
예제 #5
0
파일: server.py 프로젝트: ztzdxqj/ltp
    def serve(self, port: int = 5000, n_process: int = None):
        if n_process is None:
            n_process = 1 if sys.platform == 'win32' else 8

        fmt = LogFormatter(fmt='%(asctime)s - %(levelname)s - %(message)s',
                           datefmt='%Y-%m-%d %H:%M:%S',
                           color=True)
        root_logger = logging.getLogger()

        console_handler = logging.StreamHandler()
        file_handler = logging.FileHandler('server.log')

        console_handler.setFormatter(fmt)
        file_handler.setFormatter(fmt)

        root_logger.addHandler(console_handler)
        root_logger.addHandler(file_handler)

        app_log.setLevel(logging.INFO)
        gen_log.setLevel(logging.INFO)
        access_log.setLevel(logging.INFO)

        app_log.info("Model is loading...")
        app_log.info("Model Has Been Loaded!")

        app = Application([(r"/.*", LTPHandler, dict(ltp=self))])

        server = HTTPServer(app)
        server.bind(port)
        server.start(n_process)
        ioloop.IOLoop.instance().start()
예제 #6
0
def run(port, destport, ip, presentation_path, debug, authtype,
        request_timeout, last_activity_interval, force_alive, ready_check_path,
        command):

    if debug:
        print('Setting debug')
        app_log.setLevel(logging.DEBUG)

    prefix = os.environ.get('JUPYTERHUB_SERVICE_PREFIX', '/')

    if len(prefix) > 0 and prefix[-1] == '/':
        prefix = prefix[:-1]

    configure_http_client()

    app = make_app(destport, prefix, list(command), presentation_path,
                   authtype, request_timeout, ready_check_path, debug)

    http_server = HTTPServer(app)

    http_server.listen(port, ip)

    print(
        "Starting jhsingle-native-proxy server on address {} port {}, proxying to port {}"
        .format(ip, port, destport))
    print("URL Prefix: {}".format(prefix))
    print("Auth Type: {}".format(authtype))
    print("Command: {}".format(command))

    if last_activity_interval > 0:
        start_keep_alive(last_activity_interval, force_alive, app.settings)

    ioloop.IOLoop.current().start()
예제 #7
0
def run(port, destport, ip, presentation_path, debug, logs, authtype, request_timeout, last_activity_interval, force_alive, ready_check_path, 
        repo, repobranch, repofolder, conda_env, allow_root, notebookapp_allow_origin, forward_user_info, query_user_info, command):

    if debug:
        print('Setting debug')
        app_log.setLevel(logging.DEBUG)
    elif logs:
        app_log.setLevel(logging.INFO)

    prefix = os.environ.get('JUPYTERHUB_SERVICE_PREFIX', '/')

    if len(prefix) > 0 and prefix[-1] == '/':
        prefix = prefix[:-1]

    configure_http_client()

    app = make_app(destport, prefix, list(command), presentation_path, authtype, request_timeout, ready_check_path, 
        repo, repobranch, repofolder, conda_env, debug, logs, forward_user_info, query_user_info)

    ssl_options = get_ssl_options()

    http_server = HTTPServer(app, ssl_options=ssl_options, xheaders=True)

    http_server.listen(port, ip)

    print("Starting jhsingle-native-proxy server on address {} port {}, proxying to port {}".format(ip, port, destport))
    print("URL Prefix: {}".format(prefix))
    print("Auth Type: {}".format(authtype))
    print("Command: {}".format(command))

    if last_activity_interval > 0:
        start_keep_alive(last_activity_interval, force_alive, app.settings)

    ioloop.IOLoop.current().start()
예제 #8
0
def run(port, ip, server_name, debug, command):

    if debug:
        app_log.setLevel(logging.DEBUG)
        print('Setting debug')

    app = make_app(command, server_name, debug)

    http_server = HTTPServer(app)

    http_server.listen(port, ip)

    ioloop.IOLoop.current().start()
예제 #9
0
    def run(self):
        if options.debug:
            app_log.setLevel(logging.DEBUG)

        if not options.debug:
            fork_processes(None)
        options.port += task_id() or 0

        app_log.debug("Starting %s on port %s" % (cfg.platform_name, options.port))
        # initialize the application
        tornado.httpserver.HTTPServer(Application(self.commons)).listen(options.port, '0.0.0.0')
        ioloop = tornado.ioloop.IOLoop.instance()
        if options.debug:
            tornado.autoreload.start(ioloop)
        # enter the Tornado IO loop
        ioloop.start()
예제 #10
0
    def run(self):
        if options.debug:
            app_log.setLevel(logging.DEBUG)

        if not options.debug:
            fork_processes(None)
        options.port += task_id() or 0

        app_log.debug("Starting %s on port %s" %
                      ('tornado skeleton', options.port))
        # initialize the application
        tornado.httpserver.HTTPServer(Application(self.commons)).listen(
            options.port, '0.0.0.0')
        ioloop = tornado.ioloop.IOLoop.instance()
        if options.debug:
            tornado.autoreload.start(ioloop)
        # enter the Tornado IO loop
        ioloop.start()
예제 #11
0
def main(params):
  logging.getLogger('tornado.access').setLevel(logging.INFO)
  #logging.getLogger("tornado.application").setLevel(logging.INFO)

  from tornado.log import app_log
  #print app_log, app_log.setLevel, app_log.info
  app_log.setLevel(logging.INFO)

  app = make_app(params)
  app.listen(params.port)
  print 'started httpd on :%d' % params.port
  try:
    iptables.up(params)
  except Exception as e:
    print e.message
    exit(1)
  try:
    IOLoop.instance().start()
  except:
    iptables.down(params)
    raise
예제 #12
0
def main():
    from argparse import ArgumentParser
    parser = ArgumentParser(prog="SimpleTornadoServer",
                            description="A simple HTTP server based on tornado")
    parser.add_argument("-H", "--host", default="127.0.0.1",
                        help="Host to bind to")
    parser.add_argument("-p", "--port", type=int, default=8000,
                        help="Port to listen on")
    parser.add_argument("-r", "--root", default=".",
                        help="Root directory of the server")
    parser.add_argument("-l", "--autoindex", action="store_true",
                        help="List all files and dirs")
    parser.add_argument("-d", "--debug", action="store_true",
                        help="Debug mode")

    options = parser.parse_args()

    if options.debug:
        log.setLevel(logging.DEBUG)
    else:
        log.setLevel(logging.INFO)
    enable_pretty_logging()
    log.info('Serving site from local directory: %s' % os.path.abspath(options.root))

    handlers = [
        (r'(.*)/$', IndexHandler, dict(root=options.root, autoindex=options.autoindex)),
        (r'/(.*)$', StaticFileHandler, dict(path=options.root)),
    ]
    settings = dict(
        debug=options.debug,
        compress_response=True,
    )

    app = tornado.web.Application(handlers, **settings)
    http_server = tornado.httpserver.HTTPServer(app, xheaders=True)
    http_server.listen(options.port, options.host)
    log.info("The server is running at: http://{host}:{port}/".format(**vars(options)))
    signal.signal(signal.SIGINT, stop_server)
    tornado.ioloop.IOLoop.instance().start()
예제 #13
0
파일: app.py 프로젝트: YangTe1/chat_demo
def enable_tornado_log():
    """开启 Tornado 内置日志信息
    * ``tornado.access``: Per-request logging for Tornado's HTTP servers (and
      potentially other servers in the future)
    * ``tornado.application``: Logging of errors from application code (i.e.
      uncaught exceptions from callbacks)
    * ``tornado.general``: General-purpose logging, including any errors
      or warnings from Tornado itself.
    """
    try:
        access_log.addHandler(filehandler)
        access_log.setLevel(logger.level)

        app_log.addHandler(filehandler)
        app_log.setLevel(logger.level)

        gen_log.addHandler(filehandler)
        gen_log.setLevel(logger.level)
    except Exception:
        error_msg = traceback.format_exc()
        logger.warning(f'enable tornado log fail.\t{error_msg}')
        logger.error(f'enable tornado log fail.')
예제 #14
0
def run(port, destport, ip, debug, authtype, command):

    if debug:
        print('Setting debug')
        app_log.setLevel(logging.DEBUG)

    prefix = os.environ.get('JUPYTERHUB_SERVICE_PREFIX', '/')

    if len(prefix) > 0 and prefix[-1] == '/':
        prefix = prefix[:-1]

    app = make_app(destport, prefix, list(command), authtype, debug)

    http_server = HTTPServer(app)

    http_server.listen(port, ip)

    print(
        "Starting jhsingle-native-proxy server on address {} port {}, proxying to port {}"
        .format(ip, port, destport))
    print("URL Prefix: {}".format(prefix))
    print("Auth Type: {}".format(authtype))
    print("Command: {}".format(command))
    ioloop.IOLoop.current().start()
예제 #15
0
from models import Server

from dateutil.parser import parse as parse_date

from botocore.exceptions import ClientError, WaiterError
from concurrent.futures import ThreadPoolExecutor
from tornado.gen import coroutine, sleep
from tornado.log import app_log
from tornado.httpclient import AsyncHTTPClient, HTTPRequest, HTTPError
from tornado.ioloop import IOLoop, PeriodicCallback
from tornado.options import define, options, parse_command_line

with open("/etc/jupyterhub/server_config.json", "r") as f:
    SERVER_PARAMS = json.load(f) # load local server parameters

app_log.setLevel(logging.INFO)
logging.getLogger('boto3').setLevel(logging.ERROR)
logging.getLogger('botocore').setLevel(logging.ERROR)

thread_pool = ThreadPoolExecutor(10)

@coroutine
def retry(function, *args, **kwargs):
    """ Retries a function up to max_retries, waiting `timeout` seconds between tries.
        This function is designed to retry both boto3 and fabric calls.  In the
        case of boto3, it is necessary because sometimes aws calls return too
        early and a resource needed by the next call is not yet available. """
    max_retries = kwargs.pop("max_retries", 20)
    timeout = kwargs.pop("timeout", 0.25)
    for attempt in range(max_retries):
        try:
예제 #16
0
from tornado.options import options
from app_settings import settings
from handlers.home_handler import HomeHandler
from handlers.capture_handler import CaptureHandler
from handlers.capture_stream_handler import CaptureStreamHandler
from handlers.cast_handler import CastHandler
from handlers.cast_stream_handler import CastStreamHandler

application = tornado.web.Application(
    [(r"/scripts/(.*)", tornado.web.StaticFileHandler, {
        'path': 'scripts'
    }), (r"/", HomeHandler), (r"/capture", CaptureHandler),
     (r"/capture-stream", CaptureStreamHandler), (r"/cast/(.*)", CastHandler),
     (r"/cast-stream/(.*)", CastStreamHandler)], **settings)

if __name__ == "__main__":

    def stop_server(signum, frame):
        app_log.info('Stopping server')
        loop.stop()

    signal.signal(signal.SIGINT, stop_server)

    app_log.setLevel(options.loglevel)
    app_log.info('Starting Tornado {0} server'.format(tornado.version))
    app_log.info('Press Ctrl+C to stop')

    application.listen(options.port)
    loop = tornado.ioloop.IOLoop.current()
    loop.start()
예제 #17
0
파일: parser.py 프로젝트: esemi/web-graphs
    log_fds('start')
    log_mem('start')
    q = Q()
    s = Storage()
    parser = Parser(s)

    while True:
        log_fds('start loop')
        log_mem('start loop')
        task = q.get_parser_task()
        if task:
            yield parser.run(task[2])
            q.complete_task(task[0])
        else:
            app_log_process("not found task")
            time.sleep(options.parser_sleep_period_sec)

    app_log_process('end parser process')


if __name__ == '__main__':
    parse_command_line()

    if options.debug:
        from tornado.log import app_log
        app_log.setLevel(logging.DEBUG)

    ioloop = tornado.ioloop.IOLoop()
    ioloop.make_current()
    ioloop.run_sync(parser_process)
예제 #18
0
파일: crawler.py 프로젝트: esemi/web-graphs
    q = Q()
    s = Storage()

    while True:
        log_fds('start loop')
        log_mem('start loop')
        task = q.get_crawler_task()
        if task:
            crawler = Crawler(task[2], q, s)
            yield crawler.run()
            q.complete_task(task[0])
            del crawler
        else:
            app_log_process("not found task")
            time.sleep(options.crawler_sleep_period_sec)

    app_log_process('end crawler process')
    log_fds('end')


if __name__ == '__main__':
    parse_command_line()

    if options.debug:
        from tornado.log import app_log
        app_log.setLevel(logging.DEBUG)

    ioloop = tornado.ioloop.IOLoop()
    ioloop.make_current()
    ioloop.run_sync(crawler_process)
예제 #19
0
from handlers.home_handler import HomeHandler
from handlers.capture_handler import CaptureHandler
from handlers.capture_stream_handler import CaptureStreamHandler
from handlers.cast_handler import CastHandler
from handlers.cast_stream_handler import CastStreamHandler


application = tornado.web.Application([
    (r"/scripts/(.*)", tornado.web.StaticFileHandler, {'path': 'scripts'}),
    (r"/", HomeHandler),
    (r"/capture", CaptureHandler),
    (r"/capture-stream", CaptureStreamHandler),
    (r"/cast/(.*)", CastHandler),
    (r"/cast-stream/(.*)", CastStreamHandler)
], **settings)

if __name__ == "__main__":
    def stop_server(signum, frame):
        app_log.info('Stopping server')
        loop.stop()

    signal.signal(signal.SIGINT, stop_server)

    app_log.setLevel(options.loglevel)
    app_log.info('Starting Tornado {0} server'.format(tornado.version))
    app_log.info('Press Ctrl+C to stop')

    application.listen(options.port)
    loop = tornado.ioloop.IOLoop.current()
    loop.start()
예제 #20
0

def main():
    options.parse_command_line()

    if os.path.exists(options.configFile):
        try:
            options.parse_config_file(options.configFile)
            options.parse_command_line()
        except Exception, E:
            print("Invalid config file {0}".format(options.configFile))
            print(E)
            sys.exit(1)

    # Set Log level
    log.setLevel(getLogLevel(options.logLevel))

    if not options.cookieSecret:
        log.error("cookieSecret option required")
        sys.exit(1)

    detectProxy()
    mailer.setup(options.smtpServer, options.smtpPort, options.emailSender, options.smtpUseTLS)

    log.info("Server starting on {0}:{1}...".format(options.address, options.port))

    http_server = Application()
    http_server.listen(options.port, options.address, xheaders=True)
    io_loop = tornado.ioloop.IOLoop.instance()

    if options.autoReload:
예제 #21
0

def main():
    options.parse_command_line()

    if os.path.exists(options.configFile):
        try:
            options.parse_config_file(options.configFile)
            options.parse_command_line()
        except Exception, E:
            print("Invalid config file {0}".format(options.configFile))
            print(E)
            sys.exit(1)

    # Set Log level
    log.setLevel(getLogLevel(options.logLevel))

    detectProxy()

    # Load the credentials from file
    log.info("Loading credentials")
    try:
        credentialsFile = options.credentialsFile
        Keys.loadFromFile(credentialsFile)
    except Exception as E:
        log.error(
            "Error opening the credentials file: {0}".format(credentialsFile))
        log.error(E)
        sys.exit(1)

    # TMP fix for 'ValueError: I/O operation on closed epoll fd'