// SPDX-License-Identifier: GPL-3.0+
#include "common.h"
extern void *cgroups_main(void *ptr);
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[] = {
#ifdef INTERNAL_PLUGIN_NFACCT
// nfacct requires root access
// so, we build it as an external plugin with setuid to root
{"PLUGIN[nfacct]", CONFIG_SECTION_PLUGINS, "nfacct", 1, NULL, NULL, nfacct_main},
#endif
#ifdef NETDATA_INTERNAL_CHECKS
// debugging plugin
{"PLUGIN[check]", CONFIG_SECTION_PLUGINS, "checks", 0, NULL, NULL, checks_main},
#endif
#if defined(__FreeBSD__)
// FreeBSD internal plugins
{"PLUGIN[freebsd]", CONFIG_SECTION_PLUGINS, "freebsd", 1, NULL, NULL, freebsd_main},
#elif defined(__APPLE__)
// macOS internal plugins
{"PLUGIN[macos]", CONFIG_SECTION_PLUGINS, "macos", 1, NULL, NULL, macos_main},
#else
// linux internal plugins
{"PLUGIN[proc]", CONFIG_SECTION_PLUGINS, "proc", 1, NULL, NULL, proc_main},
{"PLUGIN[diskspace]", CONFIG_SECTION_PLUGINS, "diskspace", 1, NULL, NULL, proc_diskspace_main},
{"PLUGIN[cgroup]", CONFIG_SECTION_PLUGINS, "cgroups", 1, NULL, NULL, cgroups_main},
{"PLUGIN[tc]", CONFIG_SECTION_PLUGINS, "tc", 1, NULL, NULL, tc_main},
#endif /* __FreeBSD__, __APPLE__*/
// common plugins for all systems
{"PLUGIN[idlejitter]", CONFIG_SECTION_PLUGINS, "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
{"BACKENDS", NULL, NULL, 1, NULL, NULL, backends_main},
{"HEALTH", NULL, NULL, 1, NULL, NULL, health_main},
{"PLUGINSD", NULL, NULL, 1, NULL, NULL, pluginsd_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},
{"STATSD", NULL, NULL, 1, NULL, NULL, statsd_main},
{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_na