X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=src%2Fregistry_init.c;h=2a41d36eef13c8af8ce7be462855c6ec8b6c5fc8;hb=9dccc16d3763392f0b13349de18c3a838a667653;hp=1a086b0f72cc119f82d03ed1e7014e21ea450b83;hpb=3d239c5bf9abf9a263409fc8a2dc0c190efcdf70;p=netdata.git diff --git a/src/registry_init.c b/src/registry_init.c index 1a086b0f..2a41d36e 100644 --- a/src/registry_init.c +++ b/src/registry_init.c @@ -4,45 +4,52 @@ int registry_init(void) { char filename[FILENAME_MAX + 1]; // registry enabled? - registry.enabled = config_get_boolean("registry", "enabled", 0); + if(web_server_mode != WEB_SERVER_MODE_NONE) { + registry.enabled = config_get_boolean(CONFIG_SECTION_REGISTRY, "enabled", 0); + } + else { + info("Registry is disabled - use the central netdata"); + config_set_boolean(CONFIG_SECTION_REGISTRY, "enabled", 0); + registry.enabled = 0; + } // pathnames - registry.pathname = config_get("registry", "registry db directory", VARLIB_DIR "/registry"); + snprintfz(filename, FILENAME_MAX, "%s/registry", netdata_configured_varlib_dir); + registry.pathname = config_get(CONFIG_SECTION_REGISTRY, "registry db directory", filename); if(mkdir(registry.pathname, 0770) == -1 && errno != EEXIST) fatal("Cannot create directory '%s'.", registry.pathname); // filenames snprintfz(filename, FILENAME_MAX, "%s/netdata.public.unique.id", registry.pathname); - registry.machine_guid_filename = config_get("registry", "netdata unique id file", filename); - registry_get_this_machine_guid(); + registry.machine_guid_filename = config_get(CONFIG_SECTION_REGISTRY, "netdata unique id file", filename); snprintfz(filename, FILENAME_MAX, "%s/registry.db", registry.pathname); - registry.db_filename = config_get("registry", "registry db file", filename); + registry.db_filename = config_get(CONFIG_SECTION_REGISTRY, "registry db file", filename); snprintfz(filename, FILENAME_MAX, "%s/registry-log.db", registry.pathname); - registry.log_filename = config_get("registry", "registry log file", filename); + registry.log_filename = config_get(CONFIG_SECTION_REGISTRY, "registry log file", filename); // configuration options - registry.save_registry_every_entries = (unsigned long long)config_get_number("registry", "registry save db every new entries", 1000000); - registry.persons_expiration = config_get_number("registry", "registry expire idle persons days", 365) * 86400; - registry.registry_domain = config_get("registry", "registry domain", ""); - registry.registry_to_announce = config_get("registry", "registry to announce", "https://registry.my-netdata.io"); - registry.hostname = config_get("registry", "registry hostname", config_get("global", "hostname", localhost.hostname)); - registry.verify_cookies_redirects = config_get_boolean("registry", "verify browser cookies support", 1); + registry.save_registry_every_entries = (unsigned long long)config_get_number(CONFIG_SECTION_REGISTRY, "registry save db every new entries", 1000000); + registry.persons_expiration = config_get_number(CONFIG_SECTION_REGISTRY, "registry expire idle persons days", 365) * 86400; + registry.registry_domain = config_get(CONFIG_SECTION_REGISTRY, "registry domain", ""); + registry.registry_to_announce = config_get(CONFIG_SECTION_REGISTRY, "registry to announce", "https://registry.my-netdata.io"); + registry.hostname = config_get(CONFIG_SECTION_REGISTRY, "registry hostname", config_get(CONFIG_SECTION_GLOBAL, "hostname", "localhost")); + registry.verify_cookies_redirects = config_get_boolean(CONFIG_SECTION_REGISTRY, "verify browser cookies support", 1); setenv("NETDATA_REGISTRY_HOSTNAME", registry.hostname, 1); setenv("NETDATA_REGISTRY_URL", registry.registry_to_announce, 1); - registry.max_url_length = (size_t)config_get_number("registry", "max URL length", 1024); + registry.max_url_length = (size_t)config_get_number(CONFIG_SECTION_REGISTRY, "max URL length", 1024); if(registry.max_url_length < 10) { registry.max_url_length = 10; - config_set_number("registry", "max URL length", (long long)registry.max_url_length); + config_set_number(CONFIG_SECTION_REGISTRY, "max URL length", (long long)registry.max_url_length); } - registry.max_name_length = (size_t)config_get_number("registry", "max URL name length", 50); + registry.max_name_length = (size_t)config_get_number(CONFIG_SECTION_REGISTRY, "max URL name length", 50); if(registry.max_name_length < 10) { registry.max_name_length = 10; - config_set_number("registry", "max URL name length", (long long)registry.max_name_length); + config_set_number(CONFIG_SECTION_REGISTRY, "max URL name length", (long long)registry.max_name_length); } // initialize entries counters @@ -61,7 +68,7 @@ int registry_init(void) { registry.machines_urls_memory = 0; // initialize locks - pthread_mutex_init(®istry.lock, NULL); + netdata_mutex_init(®istry.lock); // create dictionaries registry.persons = dictionary_create(DICTIONARY_FLAGS); @@ -80,7 +87,7 @@ int registry_init(void) { return 0; } -/* + void registry_free(void) { if(!registry.enabled) return; @@ -89,32 +96,7 @@ void registry_free(void) { while(registry.persons->values_index.root) { REGISTRY_PERSON *p = ((NAME_VALUE *)registry.persons->values_index.root)->value; - - // fprintf(stderr, "\nPERSON: '%s', first: %u, last: %u, usages: %u\n", p->guid, p->first_t, p->last_t, p->usages); - - while(p->person_urls->values_index.root) { - REGISTRY_PERSON_URL *pu = ((NAME_VALUE *)p->person_urls->values_index.root)->value; - - // fprintf(stderr, "\tURL: '%s', first: %u, last: %u, usages: %u, flags: 0x%02x\n", pu->url->url, pu->first_t, pu->last_t, pu->usages, pu->flags); - - debug(D_REGISTRY, "Registry: deleting url '%s' from person '%s'", pu->url->url, p->guid); - dictionary_del(p->person_urls, pu->url->url); - - debug(D_REGISTRY, "Registry: unlinking url '%s' from person", pu->url->url); - registry_url_unlink(pu->url); - - debug(D_REGISTRY, "Registry: freeing person url"); - freez(pu); - } - - debug(D_REGISTRY, "Registry: deleting person '%s' from persons registry", p->guid); - dictionary_del(registry.persons, p->guid); - - debug(D_REGISTRY, "Registry: destroying URL dictionary of person '%s'", p->guid); - dictionary_destroy(p->person_urls); - - debug(D_REGISTRY, "Registry: freeing person '%s'", p->guid); - freez(p); + registry_person_del(p); } while(registry.machines->values_index.root) { @@ -158,4 +140,4 @@ void registry_free(void) { debug(D_REGISTRY, "Registry: destroying machines dictionary"); dictionary_destroy(registry.machines); } -*/ +