]> arthur.barton.de Git - netdata.git/commitdiff
ensure the database is always saved on exit
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 14 Jan 2017 12:19:39 +0000 (14:19 +0200)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Sat, 14 Jan 2017 12:19:39 +0000 (14:19 +0200)
src/main.c
src/rrd.c

index 5308932106511d07a20001023723b4bb38d372f0..c4869218f76fec08685058321d23f61f8c633d73 100644 (file)
@@ -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;
index 365ad87624edd24d7fba6118dee66273e9ecad65..16375c579b94f914acf78bd2df0cb7f2a19f574b 100644 (file)
--- 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);
         }