def build_app(): if os.getuid() != 0: raise RuntimeError("need to be root, sorry about that") known_env_vars = ( "MESHPING_DATABASE_PATH", "MESHPING_PING_TIMEOUT", "MESHPING_PING_INTERVAL", "MESHPING_HISTOGRAM_DAYS", "MESHPING_PEERS", "MESHPING_PEERING_INTERVAL", "MESHPING_PROMETHEUS_URL", "MESHPING_PROMETHEUS_QUERY", "MESHPING_REDIS_HOST", ) deprecated_env_vars = ( "MESHPING_PROMETHEUS_URL", "MESHPING_PROMETHEUS_QUERY", "MESHPING_REDIS_HOST", ) for key in os.environ: if key.startswith("MESHPING_") and key not in known_env_vars: print("env var %s is unknown" % key, file=sys.stderr) sys.exit(1) if key.startswith("MESHPING_") and key in deprecated_env_vars: print("env var %s is deprecated, ignored" % key, file=sys.stderr) app = QuartTrio(__name__, static_url_path="") #app.config["TEMPLATES_AUTO_RELOAD"] = True app.secret_key = str(uuid4()) app.jinja_options = dict(variable_start_string='{[', variable_end_string=']}') @app.context_processor def _inject_icons(): # I'm not happy about hardcoding this path here, but I'm also not sure what else to do icons_dir = "/opt/meshping/ui/node_modules/bootstrap-icons/icons/" return dict( icons={ filename: Markup( open(os.path.join(icons_dir, filename), "r").read()) for filename in os.listdir(icons_dir) }) mp = MeshPing(int(os.environ.get("MESHPING_PING_TIMEOUT", 5)), int(os.environ.get("MESHPING_PING_INTERVAL", 30)), int(os.environ.get("MESHPING_HISTOGRAM_DAYS", 3))) add_api_views(app, mp) @app.before_serving async def _(): app.nursery.start_soon(mp.run) app.nursery.start_soon(run_peers, mp) return app
def main(): if os.getuid() != 0: raise RuntimeError("need to be root, sorry about that") known_env_vars = ( "MESHPING_REDIS_HOST", "MESHPING_PING_TIMEOUT", "MESHPING_PING_INTERVAL", "MESHPING_PEERS", "MESHPING_PROMETHEUS_URL", "MESHPING_PROMETHEUS_QUERY", ) for key in os.environ.keys(): if key.startswith("MESHPING_") and key not in known_env_vars: print("env var %s is unknown" % key, file=sys.stderr) sys.exit(1) app = QuartTrio(__name__, static_url_path="") app.config["TEMPLATES_AUTO_RELOAD"] = True app.secret_key = str(uuid4()) app.debug = False redis = StrictRedis( host=os.environ.get("MESHPING_REDIS_HOST", "127.0.0.1")) mp = MeshPing(redis, int(os.environ.get("MESHPING_PING_TIMEOUT", 5)), int(os.environ.get("MESHPING_PING_INTERVAL", 30))) add_api_views(app, mp) @app.before_serving async def startup(): app.nursery.start_soon(mp.run) app.nursery.start_soon(run_peers, mp) app.run(host="::", port=9922)
def main(): if os.getuid() != 0: raise RuntimeError("need to be root, sorry about that") known_env_vars = ( "MESHPING_DATABASE_PATH", "MESHPING_REDIS_HOST", "MESHPING_PING_TIMEOUT", "MESHPING_PING_INTERVAL", "MESHPING_HISTOGRAM_DAYS", "MESHPING_PEERS", "MESHPING_PEERING_INTERVAL", "MESHPING_PROMETHEUS_URL", "MESHPING_PROMETHEUS_QUERY", ) deprecated_env_vars = ( "MESHPING_PROMETHEUS_URL", "MESHPING_PROMETHEUS_QUERY", ) for key in os.environ: if key.startswith("MESHPING_") and key not in known_env_vars: print("env var %s is unknown" % key, file=sys.stderr) sys.exit(1) if key.startswith("MESHPING_") and key in deprecated_env_vars: print("env var %s is deprecated, ignored" % key, file=sys.stderr) app = QuartTrio(__name__, static_url_path="") #app.config["TEMPLATES_AUTO_RELOAD"] = True app.secret_key = str(uuid4()) app.jinja_options = dict(variable_start_string='{[', variable_end_string=']}') @app.context_processor def _inject_icons(): # I'm not happy about hardcoding this path here, but I'm also not sure what else to do icons_dir = "/opt/meshping/ui/node_modules/bootstrap-icons/icons/" return dict( icons={ filename: Markup( open(os.path.join(icons_dir, filename), "r").read()) for filename in os.listdir(icons_dir) }) # Transition period: Read all targets from redis and add them to our DB try: redis = StrictRedis( host=os.environ.get("MESHPING_REDIS_HOST", "127.0.0.1")) for target in redis.smembers("meshping:targets"): target = target.decode("utf-8") name, addr = target.split("@", 1) Target.db.add(addr, name) for target in redis.smembers("meshping:foreign_targets"): target = target.decode("utf-8") name, addr = target.split("@", 1) Target.db.get(addr).set_is_foreign(True) except: # Probably no redis here, ignore pass mp = MeshPing(int(os.environ.get("MESHPING_PING_TIMEOUT", 5)), int(os.environ.get("MESHPING_PING_INTERVAL", 30)), int(os.environ.get("MESHPING_HISTOGRAM_DAYS", 3))) add_api_views(app, mp) @app.before_serving async def _(): app.nursery.start_soon(mp.run) app.nursery.start_soon(run_peers, mp) app.run(host="::", port=9922, debug=False, use_reloader=False)