Пример #1
0
def usr1_handler(signum, frame):
    assert signum == signal.SIGUSR1
    logging.info("Received USR1, reloading config.")
    try:
        IOLoop.current().add_callback_from_signal(config.load_game_data)
    except AttributeError:
        # This is for compatibility with ancient versions < Tornado 3.
        try:
            config.load_game_data()
        except Exception:
            logging.exception("Failed to update games after USR1 signal.")
    except Exception:
        logging.exception("Failed to update games after USR1 signal.")
Пример #2
0
def run():
    args = parse_args_main()
    if config.get('chroot'):
        os.chroot(config.get('chroot'))

    if config.source_file is None:
        # we could try to automatically figure this out from server_path, if
        # it is set?
        sys.exit("No configuration provided!")

    # do this here so it can happen before logging init
    if args.logfile:
        if args.logfile == "-":
            config.get('logging_config').pop('filename', None)
            args.logfile = "<stdout>"  # make the log message easier to read
        else:
            config.get('logging_config')['filename'] = args.logfile

    init_logging(config.get('logging_config'))
    logging.info("Loaded server configuration from: %s", config.source_file)

    if config.get('live_debug'):
        logging.info("Starting in live-debug mode.")
        config.set('watch_socket_dirs', False)

    if args.logfile:
        logging.info("Using command-line supplied logfile: '%s'", args.logfile)

    export_args_to_config(args)

    try:
        config.load_game_data()
        config.validate()
    except:
        err_exit("Errors in config. Exiting.", exc_info=True)

    if config.get('daemon', False):
        daemonize()

    signal.signal(signal.SIGTERM, signal_handler)
    signal.signal(signal.SIGHUP, signal_handler)
    signal.signal(signal.SIGINT, signal_handler)

    if config.get('umask') is not None:
        os.umask(config.get('umask'))

    write_pidfile()

    global servers
    servers = bind_server()
    ensure_tornado_current()

    shed_privileges()

    # is this ever set to False by anyone in practice?
    dgl_mode = config.get('dgl_mode')

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

    signal.signal(signal.SIGUSR1, usr1_handler)

    try:
        IOLoop.current().set_blocking_log_threshold(0.5)  # type: ignore
        logging.info("Blocking call timeout: 500ms.")
    except:
        # this is the new normal; still not sure of a way to deal with this.
        logging.info("Webserver running without a blocking call timeout.")

    if dgl_mode:
        ws_handler.status_file_timeout()
        auth.purge_login_tokens_timeout()
        ws_handler.start_reading_milestones()

        if config.get('watch_socket_dirs'):
            process_handler.watch_socket_dirs()

    # start the lobby update timeout loop
    ws_handler.do_periodic_lobby_updates()

    logging.info("DCSS Webtiles server started with Tornado %s! (PID: %s)" %
                 (tornado.version, os.getpid()))

    IOLoop.current().start()

    logging.info("Bye!")
    remove_pidfile()