#include "common.h"
extern void *cgroups_main(void *ptr);
void netdata_cleanup_and_exit(int ret) {
netdata_exit = 1;
error_log_limit_unlimited();
debug(D_EXIT, "Called: netdata_cleanup_and_exit()");
// save the database
rrdhost_save_all();
// unlink the pid
if(pidfile[0]) {
if(unlink(pidfile) != 0)
error("Cannot unlink pidfile '%s'.", pidfile);
}
#ifdef NETDATA_INTERNAL_CHECKS
// kill all childs
//kill_childs();
// free database
sleep(2);
rrdhost_free_all();
#endif
info("netdata 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
{"nfacct", CONFIG_SECTION_PLUGINS, "nfacct", 1, NULL, NULL, nfacct_main},
#endif
{"tc", CONFIG_SECTION_PLUGINS, "tc", 1, NULL, NULL, tc_main},
{"idlejitter", CONFIG_SECTION_PLUGINS, "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
#if defined(__FreeBSD__)
{"freebsd", CONFIG_SECTION_PLUGINS, "freebsd", 1, NULL, NULL, freebsd_main},
#elif defined(__APPLE__)
{"macos", CONFIG_SECTION_PLUGINS, "macos", 1, NULL, NULL, macos_main},
#else
{"proc", CONFIG_SECTION_PLUGINS, "proc", 1, NULL, NULL, proc_main},
{"diskspace", CONFIG_SECTION_PLUGINS, "diskspace", 1, NULL, NULL, proc_diskspace_main},
{"cgroups", CONFIG_SECTION_PLUGINS, "cgroups", 1, NULL, NULL, cgroups_main},
#endif /* __FreeBSD__, __APPLE__*/
{"check", CONFIG_SECTION_PLUGINS, "checks", 0, NULL, NULL, checks_main},
{"backends", NULL, NULL, 1, NULL, NULL, backends_main},
{"health", NULL, NULL, 1, NULL, NULL, health_main},
{"plugins.d", NULL, NULL, 1, NULL, NULL, pluginsd_main},
{"web", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
{"web-single-threaded", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
{"push-metrics", 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_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 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;
}
}
void web_server_config_options(void) {
web_client_timeout = (int)