From: Costa Tsaousis (ktsaou) Date: Sat, 14 Jan 2017 12:19:39 +0000 (+0200) Subject: ensure the database is always saved on exit X-Git-Tag: v1.5.0~20^2~8 X-Git-Url: https://arthur.barton.de/gitweb/?a=commitdiff_plain;h=bc4eed99c70910c3b3b86d16a09826885e2e1689;p=netdata.git ensure the database is always saved on exit --- diff --git a/src/main.c b/src/main.c index 53089321..c4869218 100644 --- a/src/main.c +++ b/src/main.c @@ -8,20 +8,25 @@ void netdata_cleanup_and_exit(int ret) { error_log_limit_unlimited(); debug(D_EXIT, "Called: netdata_cleanup_and_exit()"); -#ifdef NETDATA_INTERNAL_CHECKS - kill_childs(); - rrdset_free_all(); -#else + + // save the database rrdset_save_all(); -#endif - // kill_childs(); + // unlink the pid if(pidfile[0]) { if(unlink(pidfile) != 0) error("Cannot unlink pidfile '%s'.", pidfile); } - info("NetData exiting. Bye bye..."); +#ifdef NETDATA_INTERNAL_CHECKS + // kill all childs + kill_childs(); + + // free all memory + rrdset_free_all(); +#endif + + info("netdata exiting. Bye bye..."); exit(ret); } @@ -661,8 +666,7 @@ int main(int argc, char **argv) if(become_daemon(dont_fork, user) == -1) fatal("Cannot daemonize myself."); - info("NetData started on pid %d", getpid()); - + info("netdata started on pid %d.", getpid()); // ------------------------------------------------------------------------ // get default pthread stack size @@ -720,6 +724,8 @@ int main(int argc, char **argv) else debug(D_SYSTEM, "Not starting thread %s.", st->name); } + info("netdata initialization completed. Enjoy real-time performance monitoring!"); + // ------------------------------------------------------------------------ // block signals while initializing threads. sigset_t sigset; diff --git a/src/rrd.c b/src/rrd.c index 365ad876..16375c57 100644 --- a/src/rrd.c +++ b/src/rrd.c @@ -880,14 +880,7 @@ void rrdset_free_all(void) pthread_rwlock_unlock(&st->rwlock); - if(st->mapped == RRD_MEMORY_MODE_SAVE) { - debug(D_RRD_CALLS, "Saving stats '%s' to '%s'.", st->name, st->cache_filename); - savememory(st->cache_filename, st, st->memsize); - - debug(D_RRD_CALLS, "Unmapping stats '%s'.", st->name); - munmap(st, st->memsize); - } - else if(st->mapped == RRD_MEMORY_MODE_MAP) { + if(st->mapped == RRD_MEMORY_MODE_SAVE || st->mapped == RRD_MEMORY_MODE_MAP) { debug(D_RRD_CALLS, "Unmapping stats '%s'.", st->name); munmap(st, st->memsize); }