Exemplo n.º 1
0
    def __init__(self, path: str):
        """Initializes the configuration.

        :param path: path to configuration file.
        :type path: str
        """
        try:
            cfg = ConfDict.from_file(
                path, defaults={"triggers": [], "output": DEFAULT_TRACE}
            )
            ofs = len("logfiles.")
            self.logs_ = {
                k[ofs:].strip(): Path(v)
                for k, v in cfg.items()
                if k.startswith("logfiles.")
            }
            self.output_ = Path(cfg["output"])
            self.triggers_ = cfg["triggers"]
        except MissingSectionHeaderError as msh:
            sys.stderr.write(str(msh) + "\n")
            sys.exit(1)
        except ConfDict.ConfigurationError as cex:
            sys.stderr.write(
                "Configuration error. Falling back to default configuration. "
                "({})\n".format(cex)
            )
            self.logs_ = {}
            self.triggers_ = []
            self.output_ = Path(DEFAULT_TRACE)
Exemplo n.º 2
0
def main():
    import argparse

    parser = argparse.ArgumentParser(description="Start FSAL server")
    parser.add_argument("--conf", metavar="PATH", help="Path to configuration file", default=in_pkg("fsal-server.ini"))
    args, unknown = parser.parse_known_args()

    config = ConfDict.from_file(args.conf, defaults=FSAL_DEFAULTS)

    configure_logging(config)

    context = dict()
    context["config"] = config
    context["databases"] = init_databases(config)

    fs_manager = FSDBManager(config, context)
    fs_manager.start()
    context["fs_manager"] = fs_manager

    server = FSALServer(config, context)
    context["server"] = server

    def cleanup_wrapper(*args):
        cleanup(context)

    gevent.signal(signal.SIGINT, cleanup_wrapper)
    gevent.signal(signal.SIGTERM, cleanup_wrapper)

    try:
        logging.info("FSAL server started.")
        server.run()
    except KeyboardInterrupt:
        logging.info("Keyboard interrupt received. Shutting down.")
        cleanup(context)
Exemplo n.º 3
0
 def configure(self, root_dir):
     default_path = os.path.join(root_dir, self.DEFAULT_CONFIG_FILENAME)
     self.config_path = get_config_path(default=default_path)
     config = ConfDict.from_file(self.config_path,
                                 defaults=self.CONFIG_DEFAULTS)
     config['root_dir'] = root_dir
     self.config = self.app.config = config
     configure_logging(self.config)
Exemplo n.º 4
0
 def config(self):
     """
     Return component configuration. The configuration is parsed using
     confloader and return as a :py:class:`~confloader.ConfDict` instance.
     The parsed configuration is cached so accessing this property multiple
     times has no parsing overhead after the first time.
     """
     if not self._config:
         self._config = ConfDict.from_file(self.config_path)
     return self._config
Exemplo n.º 5
0
 def _load_config(self, path, strict=True):
     path = os.path.abspath(path)
     if not strict and not os.path.exists(path):
         return ConfDict()
     return ConfDict.from_file(path, defaults=self.CONFIG_DEFAULTS)
Exemplo n.º 6
0
 def _load_config(self, path, strict=True):
     path = os.path.abspath(path)
     if not strict and not os.path.exists(path):
         return ConfDict()
     return ConfDict.from_file(path, defaults=self.CONFIG_DEFAULTS)
Exemplo n.º 7
0
 def run(self, args):
     self.conf.update(ConfDict.from_file(args.conf))
     if args.debug_conf:
         pprint.pprint(self.conf, indent=4)
         self.quit(0)