Beispiel #1
0
def main ():
    def sighup_handler (server, ioloop, signum, frame):
        def stop_ioloop (ioloop):
            logging.info ("Stopping IOloop")
            ioloop.stop ()
            logging.info ("Done.")

        def stop_server (server, ioloop):
            logging.info ("Stopping HTTP server")
            server.stop ()
            ioloop.add_timeout (time.time () + 5.0, partial (stop_ioloop, ioloop))
            logging.info ("Waiting for pending requests")

        logging.info ("Graceful exit due to SIGHUP")
        ioloop.add_callback (partial (stop_server, server, ioloop))

    server = tornado.httpserver.HTTPServer (
        Application (),
        xheaders=True
    )
    server.listen (options.port, address=options.address)

    ioloop = tornado.ioloop.IOLoop.instance ()
    signal.signal (signal.SIGHUP, partial (sighup_handler, server, ioloop))

    if options.debug:
        ioloop.set_blocking_log_threshold (options.log_blocking) # issue warning if we block for log_blocking ms

    try:
        ioloop.start ()
    except KeyboardInterrupt:
        logging.info ("Exiting due to keyboard interrupt")
        raise SystemExit
Beispiel #2
0
    if umask is not None:
        os.umask(umask)

    write_pidfile()

    servers = bind_server()

    shed_privileges()

    if dgl_mode:
        userdb.ensure_user_db_exists()
    userdb.ensure_settings_db_exists()

    ioloop = tornado.ioloop.IOLoop.instance()
    ioloop.set_blocking_log_threshold(0.5)

    if dgl_mode:
        status_file_timeout()
        purge_login_tokens_timeout()
        start_reading_milestones()

        if watch_socket_dirs:
            process_handler.watch_socket_dirs()

    logging.info("Webtiles server started! (PID: %s)" % os.getpid())

    try:
        ioloop.start()
    except KeyboardInterrupt:
        logging.info("Received keyboard interrupt, shutting down.")