]> arthur.barton.de Git - netdata.git/blob - src/main.c
Merge remote-tracking branch 'upstream/master' into registry
[netdata.git] / src / main.c
1 #ifdef HAVE_CONFIG_H
2 #include <config.h>
3 #endif
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <unistd.h>
7 #include <signal.h>
8 #include <syslog.h>
9 #include <pthread.h>
10 #include <string.h>
11 #include <errno.h>
12 #include <sys/types.h>
13 #include <sys/wait.h>
14 #include <sys/time.h>
15 #include <sys/resource.h>
16 #include <sys/mman.h>
17 #include <sys/prctl.h>
18
19 #include "common.h"
20 #include "log.h"
21 #include "daemon.h"
22 #include "web_server.h"
23 #include "popen.h"
24 #include "appconfig.h"
25 #include "web_client.h"
26 #include "rrd.h"
27 #include "rrd2json.h"
28
29 #include "unit_test.h"
30
31 #include "plugins_d.h"
32 #include "plugin_idlejitter.h"
33 #include "plugin_tc.h"
34 #include "plugin_checks.h"
35 #include "plugin_proc.h"
36 #include "plugin_nfacct.h"
37 #include "registry.h"
38
39 #include "main.h"
40
41 extern void *cgroups_main(void *ptr);
42
43 volatile sig_atomic_t netdata_exit = 0;
44
45 void netdata_cleanup_and_exit(int ret)
46 {
47         netdata_exit = 1;
48         rrdset_save_all();
49         // kill_childs();
50
51         // let it log a few more error messages
52         error_log_limit_reset();
53
54         if(pidfd != -1) {
55                 if(ftruncate(pidfd, 0) != 0)
56                         error("Cannot truncate pidfile '%s'.", pidfile);
57
58                 close(pidfd);
59                 pidfd = -1;
60         }
61
62         if(pidfile[0]) {
63                 if(unlink(pidfile) != 0)
64                         error("Cannot unlink pidfile '%s'.", pidfile);
65         }
66
67         info("NetData exiting. Bye bye...");
68         exit(ret);
69 }
70
71 struct netdata_static_thread {
72         char *name;
73
74         char *config_section;
75         char *config_name;
76
77         int enabled;
78
79         pthread_t *thread;
80
81         void (*init_routine) (void);
82         void *(*start_routine) (void *);
83 };
84
85 struct netdata_static_thread static_threads[] = {
86         {"tc",                  "plugins",      "tc",                   1, NULL, NULL,  tc_main},
87         {"idlejitter",  "plugins",      "idlejitter",   1, NULL, NULL,  cpuidlejitter_main},
88         {"proc",                "plugins",      "proc",                 1, NULL, NULL,  proc_main},
89         {"cgroups",             "plugins",      "cgroups",              1, NULL, NULL,  cgroups_main},
90
91 #ifdef INTERNAL_PLUGIN_NFACCT
92         // nfacct requires root access
93         // so, we build it as an external plugin with setuid to root
94         {"nfacct",              "plugins",      "nfacct",               1, NULL, NULL,  nfacct_main},
95 #endif
96
97         {"plugins.d",   NULL,           NULL,                   1, NULL, NULL,  pluginsd_main},
98         {"check",               "plugins",      "checks",               0, NULL, NULL,  checks_main},
99         {"web",                 NULL,           NULL,                   1, NULL, NULL,  socket_listen_main},
100         {NULL,                  NULL,           NULL,                   0, NULL, NULL,  NULL}
101 };
102
103 int killpid(pid_t pid, int sig)
104 {
105         int ret = -1;
106         debug(D_EXIT, "Request to kill pid %d", pid);
107
108         errno = 0;
109         if(kill(pid, 0) == -1) {
110                 switch(errno) {
111                         case ESRCH:
112                                 error("Request to kill pid %d, but it is not running.", pid);
113                                 break;
114
115                         case EPERM:
116                                 error("Request to kill pid %d, but I do not have enough permissions.", pid);
117                                 break;
118
119                         default:
120                                 error("Request to kill pid %d, but I received an error.", pid);
121                                 break;
122                 }
123         }
124         else {
125                 errno = 0;
126                 ret = kill(pid, sig);
127                 if(ret == -1) {
128                         switch(errno) {
129                                 case ESRCH:
130                                         error("Cannot kill pid %d, but it is not running.", pid);
131                                         break;
132
133                                 case EPERM:
134                                         error("Cannot kill pid %d, but I do not have enough permissions.", pid);
135                                         break;
136
137                                 default:
138                                         error("Cannot kill pid %d, but I received an error.", pid);
139                                         break;
140                         }
141                 }
142         }
143
144         return ret;
145 }
146
147 void kill_childs()
148 {
149         siginfo_t info;
150
151         struct web_client *w;
152         for(w = web_clients; w ; w = w->next) {
153                 debug(D_EXIT, "Stopping web client %s", w->client_ip);
154                 pthread_cancel(w->thread);
155                 pthread_join(w->thread, NULL);
156         }
157
158         int i;
159         for (i = 0; static_threads[i].name != NULL ; i++) {
160                 if(static_threads[i].thread) {
161                         debug(D_EXIT, "Stopping %s thread", static_threads[i].name);
162                         pthread_cancel(*static_threads[i].thread);
163                         pthread_join(*static_threads[i].thread, NULL);
164                         static_threads[i].thread = NULL;
165                 }
166         }
167
168         if(tc_child_pid) {
169                 info("Killing tc-qos-helper procees");
170                 if(killpid(tc_child_pid, SIGTERM) != -1)
171                         waitid(P_PID, (id_t) tc_child_pid, &info, WEXITED);
172         }
173         tc_child_pid = 0;
174
175         struct plugind *cd;
176         for(cd = pluginsd_root ; cd ; cd = cd->next) {
177                 debug(D_EXIT, "Stopping %s plugin thread", cd->id);
178                 pthread_cancel(cd->thread);
179                 pthread_join(cd->thread, NULL);
180
181                 if(cd->pid && !cd->obsolete) {
182                         debug(D_EXIT, "killing %s plugin process", cd->id);
183                         if(killpid(cd->pid, SIGTERM) != -1)
184                                 waitid(P_PID, (id_t) cd->pid, &info, WEXITED);
185                 }
186         }
187
188         // if, for any reason there is any child exited
189         // catch it here
190         waitid(P_PID, 0, &info, WEXITED|WNOHANG);
191
192         debug(D_EXIT, "All threads/childs stopped.");
193 }
194
195
196 int main(int argc, char **argv)
197 {
198         int i;
199         int config_loaded = 0;
200         int dont_fork = 0;
201         size_t wanted_stacksize = 0, stacksize = 0;
202         pthread_attr_t attr;
203
204         // global initialization
205         get_HZ();
206
207         // set the name for logging
208         program_name = "netdata";
209
210         // parse  the arguments
211         for(i = 1; i < argc ; i++) {
212                 if(strcmp(argv[i], "-c") == 0 && (i+1) < argc) {
213                         if(load_config(argv[i+1], 1) != 1) {
214                                 error("Cannot load configuration file %s.", argv[i+1]);
215                                 exit(1);
216                         }
217                         else {
218                                 debug(D_OPTIONS, "Configuration loaded from %s.", argv[i+1]);
219                                 config_loaded = 1;
220                         }
221                         i++;
222                 }
223                 else if(strcmp(argv[i], "-df") == 0 && (i+1) < argc) { config_set("global", "debug flags",  argv[i+1]); debug_flags = strtoull(argv[i+1], NULL, 0); i++; }
224                 else if(strcmp(argv[i], "-p")  == 0 && (i+1) < argc) { config_set("global", "port",         argv[i+1]); i++; }
225                 else if(strcmp(argv[i], "-u")  == 0 && (i+1) < argc) { config_set("global", "run as user",  argv[i+1]); i++; }
226                 else if(strcmp(argv[i], "-l")  == 0 && (i+1) < argc) { config_set("global", "history",      argv[i+1]); i++; }
227                 else if(strcmp(argv[i], "-t")  == 0 && (i+1) < argc) { config_set("global", "update every", argv[i+1]); i++; }
228                 else if(strcmp(argv[i], "-ch") == 0 && (i+1) < argc) { config_set("global", "host access prefix", argv[i+1]); i++; }
229                 else if(strcmp(argv[i], "-stacksize") == 0 && (i+1) < argc) { config_set("global", "pthread stack size", argv[i+1]); i++; }
230                 else if(strcmp(argv[i], "-nodaemon") == 0 || strcmp(argv[i], "-nd") == 0) dont_fork = 1;
231                 else if(strcmp(argv[i], "-pidfile") == 0 && (i+1) < argc) {
232                         i++;
233                         strncpy(pidfile, argv[i], FILENAME_MAX);
234                         pidfile[FILENAME_MAX] = '\0';
235                 }
236                 else if(strcmp(argv[i], "--unittest")  == 0) {
237                         rrd_update_every = 1;
238                         if(run_all_mockup_tests()) exit(1);
239                         if(unit_test_storage()) exit(1);
240                         fprintf(stderr, "\n\nALL TESTS PASSED\n\n");
241                         exit(0);
242                 }
243                 else {
244                         fprintf(stderr, "Cannot understand option '%s'.\n", argv[i]);
245                         fprintf(stderr, "\nUSAGE: %s [-d] [-l LINES_TO_SAVE] [-u UPDATE_TIMER] [-p LISTEN_PORT] [-df debug flags].\n\n", argv[0]);
246                         fprintf(stderr, "  -c CONFIG FILE the configuration file to load. Default: %s.\n", CONFIG_DIR "/" CONFIG_FILENAME);
247                         fprintf(stderr, "  -l LINES_TO_SAVE can be from 5 to %d lines in JSON data. Default: %d.\n", RRD_HISTORY_ENTRIES_MAX, RRD_DEFAULT_HISTORY_ENTRIES);
248                         fprintf(stderr, "  -t UPDATE_TIMER can be from 1 to %d seconds. Default: %d.\n", UPDATE_EVERY_MAX, UPDATE_EVERY);
249                         fprintf(stderr, "  -p LISTEN_PORT can be from 1 to %d. Default: %d.\n", 65535, LISTEN_PORT);
250                         fprintf(stderr, "  -u USERNAME can be any system username to run as. Default: none.\n");
251                         fprintf(stderr, "  -ch path to access host /proc and /sys when running in a container. Default: empty.\n");
252                         fprintf(stderr, "  -nd or -nodeamon to disable forking in the background. Default: unset.\n");
253                         fprintf(stderr, "  -df FLAGS debug options. Default: 0x%08llx.\n", debug_flags);
254                         fprintf(stderr, "  -stacksize BYTES to overwrite the pthread stack size.\n");
255                         fprintf(stderr, "  -pidfile FILENAME to save a pid while running.\n");
256                         exit(1);
257                 }
258         }
259
260         if(!config_loaded) load_config(NULL, 0);
261
262         // prepare configuration environment variables for the plugins
263         setenv("NETDATA_CONFIG_DIR" , config_get("global", "config directory"   , CONFIG_DIR) , 1);
264         setenv("NETDATA_PLUGINS_DIR", config_get("global", "plugins directory"  , PLUGINS_DIR), 1);
265         setenv("NETDATA_WEB_DIR"    , config_get("global", "web files directory", WEB_DIR)    , 1);
266         setenv("NETDATA_CACHE_DIR"  , config_get("global", "cache directory"    , CACHE_DIR)  , 1);
267         setenv("NETDATA_LIB_DIR"    , config_get("global", "lib directory"      , VARLIB_DIR) , 1);
268         setenv("NETDATA_LOG_DIR"    , config_get("global", "log directory"      , LOG_DIR)    , 1);
269         setenv("NETDATA_HOST_PREFIX", config_get("global", "host access prefix" , "")         , 1);
270         setenv("HOME"               , config_get("global", "home directory"     , CACHE_DIR)  , 1);
271
272         // avoid extended to stat(/etc/localtime)
273         // http://stackoverflow.com/questions/4554271/how-to-avoid-excessive-stat-etc-localtime-calls-in-strftime-on-linux
274         setenv("TZ", ":/etc/localtime", 0);
275
276         // cd to /tmp to avoid any plugins writing files at random places
277         if(chdir("/tmp")) error("netdata: ERROR: Cannot cd to /tmp");
278
279         char *input_log_file = NULL;
280         char *output_log_file = NULL;
281         char *error_log_file = NULL;
282         char *access_log_file = NULL;
283         char *user = NULL;
284         {
285                 char buffer[1024];
286
287                 // --------------------------------------------------------------------
288
289                 sprintf(buffer, "0x%08llx", 0ULL);
290                 char *flags = config_get("global", "debug flags", buffer);
291                 setenv("NETDATA_DEBUG_FLAGS", flags, 1);
292
293                 debug_flags = strtoull(flags, NULL, 0);
294                 debug(D_OPTIONS, "Debug flags set to '0x%8llx'.", debug_flags);
295
296                 if(debug_flags != 0) {
297                         struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
298                         if(setrlimit(RLIMIT_CORE, &rl) != 0)
299                                 info("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
300                         prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
301                 }
302
303                 // --------------------------------------------------------------------
304
305 #ifdef MADV_MERGEABLE
306                 enable_ksm = config_get_boolean("global", "memory deduplication (ksm)", enable_ksm);
307 #else
308 #warning "Kernel memory deduplication (KSM) is not available"
309 #endif
310
311                 // --------------------------------------------------------------------
312
313
314                 global_host_prefix = config_get("global", "host access prefix", "");
315                 setenv("NETDATA_HOST_PREFIX", global_host_prefix, 1);
316
317                 // --------------------------------------------------------------------
318
319                 output_log_file = config_get("global", "debug log", LOG_DIR "/debug.log");
320                 if(strcmp(output_log_file, "syslog") == 0) {
321                         output_log_syslog = 1;
322                         output_log_file = NULL;
323                 }
324                 else if(strcmp(output_log_file, "none") == 0) {
325                         output_log_syslog = 0;
326                         output_log_file = NULL;
327                 }
328                 else output_log_syslog = 0;
329
330                 // --------------------------------------------------------------------
331
332                 error_log_file = config_get("global", "error log", LOG_DIR "/error.log");
333                 if(strcmp(error_log_file, "syslog") == 0) {
334                         error_log_syslog = 1;
335                         error_log_file = NULL;
336                 }
337                 else if(strcmp(error_log_file, "none") == 0) {
338                         error_log_syslog = 0;
339                         error_log_file = NULL;
340                         // optimization - do not even generate debug log entries
341                 }
342                 else error_log_syslog = 0;
343
344                 error_log_throttle_period = config_get_number("global", "errors flood protection period", error_log_throttle_period);
345                 setenv("NETDATA_ERRORS_THROTTLE_PERIOD", config_get("global", "errors flood protection period"    , ""), 1);
346
347                 error_log_errors_per_period = config_get_number("global", "errors to trigger flood protection", error_log_errors_per_period);
348                 setenv("NETDATA_ERRORS_PER_PERIOD"     , config_get("global", "errors to trigger flood protection", ""), 1);
349
350                 // --------------------------------------------------------------------
351
352                 access_log_file = config_get("global", "access log", LOG_DIR "/access.log");
353                 if(strcmp(access_log_file, "syslog") == 0) {
354                         access_log_syslog = 1;
355                         access_log_file = NULL;
356                 }
357                 else if(strcmp(access_log_file, "none") == 0) {
358                         access_log_syslog = 0;
359                         access_log_file = NULL;
360                 }
361                 else access_log_syslog = 0;
362
363                 // --------------------------------------------------------------------
364
365                 rrd_memory_mode = rrd_memory_mode_id(config_get("global", "memory mode", rrd_memory_mode_name(rrd_memory_mode)));
366
367                 // --------------------------------------------------------------------
368
369                 if(gethostname(buffer, HOSTNAME_MAX) == -1)
370                         error("WARNING: Cannot get machine hostname.");
371                 hostname = config_get("global", "hostname", buffer);
372                 debug(D_OPTIONS, "hostname set to '%s'", hostname);
373
374                 // --------------------------------------------------------------------
375
376                 rrd_default_history_entries = (int) config_get_number("global", "history", RRD_DEFAULT_HISTORY_ENTRIES);
377                 if(rrd_default_history_entries < 5 || rrd_default_history_entries > RRD_HISTORY_ENTRIES_MAX) {
378                         info("Invalid save lines %d given. Defaulting to %d.", rrd_default_history_entries, RRD_DEFAULT_HISTORY_ENTRIES);
379                         rrd_default_history_entries = RRD_DEFAULT_HISTORY_ENTRIES;
380                 }
381                 else {
382                         debug(D_OPTIONS, "save lines set to %d.", rrd_default_history_entries);
383                 }
384
385                 // --------------------------------------------------------------------
386
387                 rrd_update_every = (int) config_get_number("global", "update every", UPDATE_EVERY);
388                 if(rrd_update_every < 1 || rrd_update_every > 600) {
389                         info("Invalid update timer %d given. Defaulting to %d.", rrd_update_every, UPDATE_EVERY_MAX);
390                         rrd_update_every = UPDATE_EVERY;
391                 }
392                 else debug(D_OPTIONS, "update timer set to %d.", rrd_update_every);
393
394                 // let the plugins know the min update_every
395                 {
396                         char buf[50];
397                         snprintf(buf, 50, "%d", rrd_update_every);
398                         setenv("NETDATA_UPDATE_EVERY", buf, 1);
399                 }
400
401                 // --------------------------------------------------------------------
402
403                 // block signals while initializing threads.
404                 // this causes the threads to block signals.
405                 sigset_t sigset;
406                 sigfillset(&sigset);
407
408                 if(pthread_sigmask(SIG_BLOCK, &sigset, NULL) == -1) {
409                         error("Could not block signals for threads");
410                 }
411
412                 // Catch signals which we want to use to quit savely
413                 struct sigaction sa;
414                 sigemptyset(&sa.sa_mask);
415                 sigaddset(&sa.sa_mask, SIGHUP);
416                 sigaddset(&sa.sa_mask, SIGINT);
417                 sigaddset(&sa.sa_mask, SIGTERM);
418                 sa.sa_handler = sig_handler;
419                 if(sigaction(SIGHUP, &sa, NULL) == -1) {
420                         error("Failed to change signal handler for SIGHUP");
421                 }
422                 if(sigaction(SIGINT, &sa, NULL) == -1) {
423                         error("Failed to change signal handler for SIGINT");
424                 }
425                 if(sigaction(SIGTERM, &sa, NULL) == -1) {
426                         error("Failed to change signal handler for SIGTERM");
427                 }
428                 // Ignore SIGPIPE completely.
429                 // INFO: If we add signals here we have to unblock them
430                 // at popen.c when running a external plugin.
431                 sa.sa_handler = SIG_IGN;
432                 if(sigaction(SIGPIPE, &sa, NULL) == -1) {
433                         error("Failed to change signal handler for SIGTERM");
434                 }
435
436                 // --------------------------------------------------------------------
437
438                 i = pthread_attr_init(&attr);
439                 if(i != 0)
440                         fatal("pthread_attr_init() failed with code %d.", i);
441
442                 i = pthread_attr_getstacksize(&attr, &stacksize);
443                 if(i != 0)
444                         fatal("pthread_attr_getstacksize() failed with code %d.", i);
445                 else
446                         debug(D_OPTIONS, "initial pthread stack size is %zu bytes", stacksize);
447
448                 wanted_stacksize = config_get_number("global", "pthread stack size", stacksize);
449
450                 // --------------------------------------------------------------------
451
452                 for (i = 0; static_threads[i].name != NULL ; i++) {
453                         struct netdata_static_thread *st = &static_threads[i];
454
455                         if(st->config_name) st->enabled = config_get_boolean(st->config_section, st->config_name, st->enabled);
456                         if(st->enabled && st->init_routine) st->init_routine();
457                 }
458
459                 // --------------------------------------------------------------------
460
461                 // get the user we should run
462                 // IMPORTANT: this is required before web_files_uid()
463                 user = config_get("global", "run as user"    , (getuid() == 0)?NETDATA_USER:"");
464
465                 // IMPORTANT: these have to run once, while single threaded
466                 web_files_uid(); // IMPORTANT: web_files_uid() before web_files_gid()
467                 web_files_gid();
468
469                 // --------------------------------------------------------------------
470
471                 listen_backlog = (int) config_get_number("global", "http port listen backlog", LISTEN_BACKLOG);
472
473                 listen_port = (int) config_get_number("global", "port", LISTEN_PORT);
474                 if(listen_port < 1 || listen_port > 65535) {
475                         info("Invalid listen port %d given. Defaulting to %d.", listen_port, LISTEN_PORT);
476                         listen_port = LISTEN_PORT;
477                 }
478                 else debug(D_OPTIONS, "Listen port set to %d.", listen_port);
479
480                 int ip = 0;
481                 char *ipv = config_get("global", "ip version", "any");
482                 if(!strcmp(ipv, "any") || !strcmp(ipv, "both") || !strcmp(ipv, "all")) ip = 0;
483                 else if(!strcmp(ipv, "ipv4") || !strcmp(ipv, "IPV4") || !strcmp(ipv, "IPv4") || !strcmp(ipv, "4")) ip = 4;
484                 else if(!strcmp(ipv, "ipv6") || !strcmp(ipv, "IPV6") || !strcmp(ipv, "IPv6") || !strcmp(ipv, "6")) ip = 6;
485                 else info("Cannot understand ip version '%s'. Assuming 'any'.", ipv);
486
487                 if(ip == 0 || ip == 6) listen_fd = create_listen_socket6(config_get("global", "bind socket to IP", "*"), listen_port, listen_backlog);
488                 if(listen_fd < 0) {
489                         listen_fd = create_listen_socket4(config_get("global", "bind socket to IP", "*"), listen_port, listen_backlog);
490                         if(listen_fd >= 0 && ip != 4) info("Managed to open an IPv4 socket on port %d.", listen_port);
491                 }
492
493                 if(listen_fd < 0) fatal("Cannot listen socket.");
494         }
495
496         // never become a problem
497         if(nice(20) == -1) error("Cannot lower my CPU priority.");
498
499         if(become_daemon(dont_fork, 0, user, input_log_file, output_log_file, error_log_file, access_log_file, &access_fd, &stdaccess) == -1) {
500                 fatal("Cannot demonize myself.");
501                 exit(1);
502         }
503
504         if(debug_flags != 0) {
505                 struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
506                 if(setrlimit(RLIMIT_CORE, &rl) != 0)
507                         info("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
508
509                 prctl(PR_SET_DUMPABLE, 1, 0, 0, 0);
510         }
511
512         if(output_log_syslog || error_log_syslog || access_log_syslog)
513                 openlog("netdata", LOG_PID, LOG_DAEMON);
514
515         info("NetData started on pid %d", getpid());
516
517
518
519         // ------------------------------------------------------------------------
520         // get default pthread stack size
521
522         if(stacksize < wanted_stacksize) {
523                 i = pthread_attr_setstacksize(&attr, wanted_stacksize);
524                 if(i != 0)
525                         fatal("pthread_attr_setstacksize() to %zu bytes, failed with code %d.", wanted_stacksize, i);
526                 else
527                         info("Successfully set pthread stacksize to %zu bytes", wanted_stacksize);
528         }
529
530         // --------------------------------------------------------------------
531         // initialize the registry
532
533         registry_init();
534
535
536         // ------------------------------------------------------------------------
537         // spawn the threads
538
539         for (i = 0; static_threads[i].name != NULL ; i++) {
540                 struct netdata_static_thread *st = &static_threads[i];
541
542                 if(st->enabled) {
543                         st->thread = malloc(sizeof(pthread_t));
544                         if(!st->thread)
545                                 fatal("Cannot allocate pthread_t memory");
546
547                         info("Starting thread %s.", st->name);
548
549                         if(pthread_create(st->thread, &attr, st->start_routine, NULL))
550                                 error("failed to create new thread for %s.", st->name);
551
552                         else if(pthread_detach(*st->thread))
553                                 error("Cannot request detach of newly created %s thread.", st->name);
554                 }
555                 else info("Not starting thread %s.", st->name);
556         }
557
558         // ------------------------------------------------------------------------
559         // block signals while initializing threads.
560         sigset_t sigset;
561         sigfillset(&sigset);
562
563         if(pthread_sigmask(SIG_UNBLOCK, &sigset, NULL) == -1) {
564                 error("Could not unblock signals for threads");
565         }
566
567         // Handle flags set in the signal handler.
568         while(1) {
569                 pause();
570                 if(netdata_exit) {
571                         info("Exit main loop of netdata.");
572                         netdata_cleanup_and_exit(0);
573                         exit(0);
574                 }
575         }
576 }