Exemple #1
0
static int child_main() {
  eventer_t e;

  /* Load our config...
   * to ensure it is current w.r.t. to this child starting */
  if(noit_conf_load(config_file) == -1) {
    noitL(noit_error, "Cannot load config: '%s'\n", config_file);
    exit(2);
  }

  noit_log_reopen_all();

  signal(SIGHUP, request_conf_reload);

  /* initialize the eventer */
  if(eventer_init() == -1) {
    noitL(noit_stderr, "Cannot initialize eventer\n");
    exit(-1);
  }
  /* rotation init requires, eventer_init() */
  noit_conf_log_init_rotate(APPNAME, noit_false);

  /* Setup our heartbeat */
  noit_watchdog_child_eventer_heartbeat();

  e = eventer_alloc();
  e->mask = EVENTER_RECURRENT;
  e->callback = noitice_hup;
  eventer_add_recurrent(e);

  /* Initialize all of our listeners */
  noit_console_init(APPNAME);
  noit_console_conf_init();
  noit_console_conf_checks_init();
  noit_capabilities_listener_init();
  noit_jlog_listener_init();
  noit_http_rest_init();
  noit_check_rest_init();
  noit_filters_rest_init();
  noit_livestream_listener_init();

  noit_module_init();
  if(strict_module_load && noit_module_load_failures() > 0) {
    noitL(noit_stderr, "Failed to load some modules and -M given.\n");
    exit(2);
  }

  /* Drop privileges */
  if(chrootpath && noit_security_chroot(chrootpath)) {
    noitL(noit_stderr, "Failed to chroot(), exiting.\n");
    exit(2);
  }
  if(noit_security_usergroup(droptouser, droptogroup, noit_false)) {
    noitL(noit_stderr, "Failed to drop privileges, exiting.\n");
    exit(2);
  }

  /* Prepare for launch... */
  noit_filters_init();
  noit_poller_init();
  noit_listener_init(APPNAME);

  /* Write our log out, and setup a watchdog to write it out on change. */
  noit_conf_write_log(NULL);
  noit_conf_coalesce_changes(10); /* 10 seconds of no changes before we write */
  noit_conf_watch_and_journal_watchdog(noit_conf_write_log, NULL);

  eventer_loop();
  return 0;
}
Exemple #2
0
static int child_main() {
  char conf_str[1024];

  /* Next (re)load the configs */
  if(noit_conf_load(config_file) == -1) {
    fprintf(stderr, "Cannot load config: '%s'\n", config_file);
    exit(2);
  }

  noit_log_reopen_all();

  /* Lastly, run through all other system inits */
  if(!noit_conf_get_stringbuf(NULL, "/" APPNAME "/eventer/@implementation",
                              conf_str, sizeof(conf_str))) {
    noitL(noit_stderr, "Cannot find '%s' in configuration\n",
          "/" APPNAME "/eventer/@implementation");
    exit(2);
  }
  if(eventer_choose(conf_str) == -1) {
    noitL(noit_stderr, "Cannot choose eventer %s\n", conf_str);
    exit(2);
  }
  if(configure_eventer() != 0) {
    noitL(noit_stderr, "Cannot configure eventer\n");
    exit(2);
  }
  if(eventer_init() == -1) {
    noitL(noit_stderr, "Cannot init eventer %s\n", conf_str);
    exit(2);
  }
  /* rotation init requires, eventer_init() */
  noit_conf_log_init_rotate(APPNAME, noit_false);

  noit_watchdog_child_eventer_heartbeat();

  noit_console_init(APPNAME);
  noit_console_conf_init();
  noit_http_rest_init();
  stratcon_realtime_http_init(APPNAME);
  noit_capabilities_listener_init();
  noit_listener_init(APPNAME);

  noit_module_init();
  if(strict_module_load && noit_module_load_failures() > 0) {
    noitL(noit_stderr, "Failed to load some modules and -M given.\n");
    exit(2);
  }

  if(stratcon_datastore_get_enabled())
    stratcon_datastore_init();

  /* Drop privileges */
  if(chrootpath && noit_security_chroot(chrootpath)) {
    noitL(noit_stderr, "Failed to chroot(), exiting.\n");
    exit(-1);
  }
  if(noit_security_usergroup(droptouser, droptogroup, noit_false)) {
    noitL(noit_stderr, "Failed to drop privileges, exiting.\n");
    exit(-1);
  }

  stratcon_jlog_streamer_init(APPNAME);

  if(stratcon_iep_get_enabled())
    stratcon_iep_init();
  if(stratcon_datastore_get_enabled()) {
    /* Write our log out, and setup a watchdog to write it out on change. */
    stratcon_datastore_saveconfig(NULL);
    noit_conf_coalesce_changes(10); /* 10 seconds of no changes before we write */
  }
  else
    noit_conf_coalesce_changes(INT_MAX);

  noit_conf_watch_and_journal_watchdog(stratcon_datastore_saveconfig, NULL);

  eventer_loop();
  return 0;
}