// SPDX-License-Identifier: GPL-3.0-or-later
#include "common.h"
int netdata_anonymous_statistics_enabled;
struct config netdata_config = {
.sections = NULL,
.mutex = NETDATA_MUTEX_INITIALIZER,
.index = {
.avl_tree = {
.root = NULL,
.compar = appconfig_section_compare
},
.rwlock = AVL_LOCK_INITIALIZER
}
};
void netdata_cleanup_and_exit(int ret) {
// enabling this, is wrong
// because the threads will be cancelled while cleaning up
// netdata_exit = 1;
error_log_limit_unlimited();
info("EXIT: netdata prepares to exit with code %d...", ret);
send_statistics("EXIT", ret?"ERROR":"OK","-");
// cleanup/save the database and exit
info("EXIT: cleaning up the database...");
rrdhost_cleanup_all();
if(!ret) {
// exit cleanly
// stop everything
info("EXIT: stopping master threads...");
cancel_main_threads();
// free the database
info("EXIT: freeing database memory...");
rrdhost_free_all();
}
// unlink the pid
if(pidfile[0]) {
info("EXIT: removing netdata PID file '%s'...", pidfile);
if(unlink(pidfile) != 0)
error("EXIT: cannot unlink pidfile '%s'.", pidfile);
}
info("EXIT: all done - netdata is now exiting - bye bye...");
exit(ret);
}
struct netdata_static_thread static_threads[] = {
NETDATA_PLUGIN_HOOK_CHECKS
NETDATA_PLUGIN_HOOK_FREEBSD
NETDATA_PLUGIN_HOOK_MACOS
// linux internal plugins
NETDATA_PLUGIN_HOOK_LINUX_NFACCT
NETDATA_PLUGIN_HOOK_LINUX_PROC
NETDATA_PLUGIN_HOOK_LINUX_DISKSPACE
NETDATA_PLUGIN_HOOK_LINUX_CGROUPS
NETDATA_PLUGIN_HOOK_LINUX_TC
NETDATA_PLUGIN_HOOK_IDLEJITTER
NETDATA_PLUGIN_HOOK_STATSD
// common plugins for all systems
{"BACKENDS", NULL, NULL, 1, NULL, NULL, backends_main},
{"WEB_SERVER[static1]", NULL, NULL, 0, NULL, NULL, socket_listen_main_static_threaded},
{"STREAM", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
NETDATA_PLUGIN_HOOK_PLUGINSD
NETDATA_PLUGIN_HOOK_HEALTH
{NULL, NULL, NULL, 0, NULL, NULL, NULL}
};
void web_server_threading_selection(void) {
web_server_mode = web_server_mode_id(config_get(CONFIG_SECTION_WEB, "mode", web_server_mode_name(web_server_mode)));
int static_threaded = (web_server_mode == WEB_SERVER_MODE_STATIC_THREADED);
int i;
for (i = 0; static_threads[i].name; i++) {
if (static_threads[i].start_routine == socket_listen_main_static_threaded)
static_threads[i].enabled = static_threaded;
}
}
void web_server_config_options(void) {
web_client_timeout = (int) config_get_number(CONFIG_SECTION_WEB, "disconnect idle clients after seconds", web_client_timeout);
web_client_first_request_timeout = (int) config_get_number(CONFIG_SECTION_WEB, "timeout for first request", web_client_first_request_timeout);
web_client_streaming_rate_t = config_get_number(CONFIG_SECTION_WEB, "accept a streaming request every seconds", web_client_streaming_rate_t);
respect_web_browser_do_not_track_policy = config_get_boolean(CONFIG_SECTION_WEB, "respect do not track policy",