// SPDX-License-Identifier: GPL-3.0-or-later
#include "common.h"
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);
// 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[multi]", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
{"WEB_SERVER[single]", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
{"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 multi_threaded = (web_server_mode == WEB_SERVER_MODE_MULTI_THREADED);
int single_threaded = (web_server_mode == WEB_SERVER_MODE_SINGLE_THREADED);
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_multi_threaded)
static_threads[i].enabled = multi_threaded;
if (static_threads[i].start_routine == socket_listen_main_single_threaded)
static_threads[i].enabled = single_threaded;
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)