Exemple #1
0
def main(unused_argv):
  """Main."""
  # Change the startup sequence in order to set the database path, if needed.
  config_lib.SetPlatformArchContext()
  config_lib.CONFIG.AddContext(contexts.DATA_SERVER_CONTEXT,
                               "Context applied when running a data server.")
  config_lib.ParseConfigCommandLine()

  if flags.FLAGS.path:
    config_lib.CONFIG.Set("Datastore.location", flags.FLAGS.path)

  log.ServerLoggingStartupInit()
  stats.STATS = stats.StatsCollector()

  # We avoid starting some hooks because they add unneeded things
  # to the data store.
  do_not_start = set(
      ["ConfigurationViewInitHook", "FileStoreInit", "GRRAFF4Init"])
  registry.Init(skip_set=do_not_start)

  if flags.FLAGS.ipv6:
    af = socket.AF_INET6
  else:
    af = socket.AF_INET

  Start(
      data_store.DB,
      port=flags.FLAGS.port,
      address_family=af,
      is_master=flags.FLAGS.master)
Exemple #2
0
def TestInit():
    """Only used in tests and will rerun all the hooks to create a clean state."""
    global INIT_RAN

    if stats.STATS is None:
        stats.STATS = stats.StatsCollector()

    # Tests use both the server template grr_server.yaml as a primary config file
    # (this file does not contain all required options, e.g. private keys), and
    # additional configuration in test_data/grr_test.yaml which contains typical
    # values for a complete installation.
    flags.FLAGS.config = config_lib.Resource().Filter(
        "install_data/etc/grr-server.yaml")

    flags.FLAGS.secondary_configs.append(config_lib.Resource().Filter(
        "test_data/grr_test.yaml@grr-response-test"))

    # This config contains non-public settings that should be applied during
    # tests.
    extra_test_config = config.CONFIG["Test.additional_test_config"]
    if os.path.exists(extra_test_config):
        flags.FLAGS.secondary_configs.append(extra_test_config)

    # Tests additionally add a test configuration file.
    config_lib.SetPlatformArchContext()
    config_lib.ParseConfigCommandLine()

    # We are running a test so let the config system know that.
    config.CONFIG.AddContext(contexts.TEST_CONTEXT,
                             "Context applied when we run tests.")

    test_ds = flags.FLAGS.test_data_store
    if test_ds is None:
        test_ds = fake_data_store.FakeDataStore.__name__

    config.CONFIG.Set("Datastore.implementation", test_ds)
    config.CONFIG.Set("Blobstore.implementation",
                      memory_stream_bs.MemoryStreamBlobstore.__name__)

    if not INIT_RAN:
        log.ServerLoggingStartupInit()

    registry.TestInit()

    db = data_store.DB.SetupTestDB()
    if db:
        data_store.DB = db
    data_store.DB.Initialize()
    aff4.AFF4InitHook().Run()

    INIT_RAN = True
Exemple #3
0
def Init():
    """Run all required startup routines and initialization hooks."""
    global INIT_RAN
    if INIT_RAN:
        return

    if hasattr(local, "stats"):
        stats.STATS = local.stats.StatsCollector()
    else:
        stats.STATS = stats.StatsCollector()

    # Set up a temporary syslog handler so we have somewhere to log problems
    # with ConfigInit() which needs to happen before we can start our create our
    # proper logging setup.
    syslog_logger = logging.getLogger("TempLogger")
    if os.path.exists("/dev/log"):
        handler = logging.handlers.SysLogHandler(address="/dev/log")
    else:
        handler = logging.handlers.SysLogHandler()
    syslog_logger.addHandler(handler)

    try:
        config_lib.SetPlatformArchContext()
        config_lib.ParseConfigCommandLine()
    except config_lib.Error:
        syslog_logger.exception("Died during config initialization")
        raise

    log.ServerLoggingStartupInit()
    registry.Init()

    # Exempt config updater from this check because it is the one responsible for
    # setting the variable.
    if not config.CONFIG.ContextApplied("ConfigUpdater Context"):
        if not config.CONFIG.Get("Server.initialized"):
            raise RuntimeError(
                "Config not initialized, run \"grr_config_updater"
                " initialize\". If the server is already configured,"
                " add \"Server.initialized: True\" to your config.")

    INIT_RAN = True
Exemple #4
0
def TestInit():
  """Only used in tests and will rerun all the hooks to create a clean state."""
  global INIT_RAN

  if stats.STATS is None:
    stats.STATS = stats.StatsCollector()

  # Tests use both the server template grr_server.yaml as a primary config file
  # (this file does not contain all required options, e.g. private keys), and
  # additional configuration in test_data/grr_test.yaml which contains typical
  # values for a complete installation.
  flags.FLAGS.config = config_lib.Resource().Filter(
      "install_data/etc/grr-server.yaml")

  flags.FLAGS.secondary_configs = [
      config_lib.Resource().Filter("test_data/grr_test.yaml@grr-response-test")
  ]

  # This config contains non-public settings that should be applied during
  # tests.
  extra_test_config = config_lib.CONFIG["Test.additional_test_config"]
  if os.path.exists(extra_test_config):
    flags.FLAGS.secondary_configs.append(extra_test_config)

  # We are running a test so let the config system know that.
  config_lib.CONFIG.AddContext("Test Context",
                               "Context applied when we run tests.")

  # Tests additionally add a test configuration file.
  config_lib.SetPlatformArchContext()
  config_lib.ParseConfigCommandLine()

  if not INIT_RAN:
    log.ServerLoggingStartupInit()

  registry.TestInit()

  INIT_RAN = True