]> arthur.barton.de Git - netdata.git/commitdiff
SIGUSR1 saves the database
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 15 Jul 2016 18:42:53 +0000 (21:42 +0300)
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>
Fri, 15 Jul 2016 18:42:53 +0000 (21:42 +0300)
src/daemon.c
src/daemon.h
src/main.c
src/popen.c

index 33d3d0c1d819dfc2e10523f3825dbdd0b06c97bb..b14b4d9a4a2d8adbded457fe9e686a855d6df1df 100644 (file)
@@ -27,7 +27,7 @@
 
 char pidfile[FILENAME_MAX + 1] = "";
 
-void sig_handler(int signo)
+void sig_handler_exit(int signo)
 {
        if(signo) {
                error_log_limit_unlimited();
@@ -36,6 +36,14 @@ void sig_handler(int signo)
        }
 }
 
+void sig_handler_save(int signo)
+{
+       if(signo) {
+               info("Received signal %d to save the database...", signo);
+               rrdset_save_all();
+       }
+}
+
 static void properly_chown_netdata_generated_file(int fd, uid_t uid, gid_t gid) {
        if(fd == -1) return;
 
index 4b08c852780621692a87f0026c8cac165190373c..8d62469b65a1b611db8da530407f56a466ecf3cb 100644 (file)
@@ -1,7 +1,8 @@
 #ifndef NETDATA_DAEMON_H
 #define NETDATA_DAEMON_H 1
 
-extern void sig_handler(int signo);
+extern void sig_handler_exit(int signo);
+extern void sig_handler_save(int signo);
 
 extern int become_user(const char *username, int access_fd, int output_fd, int error_fd, int pid_fd);
 
index d79bf668a6156713b1deca847fd7b7ba19e5628e..b3471f732048e40d012817baaedc5002d95fc36c 100644 (file)
@@ -591,7 +591,7 @@ int main(int argc, char **argv)
                sigaddset(&sa.sa_mask, SIGHUP);
                sigaddset(&sa.sa_mask, SIGINT);
                sigaddset(&sa.sa_mask, SIGTERM);
-               sa.sa_handler = sig_handler;
+               sa.sa_handler = sig_handler_exit;
                sa.sa_flags = 0;
                if(sigaction(SIGHUP, &sa, NULL) == -1) {
                        error("Failed to change signal handler for SIGHUP");
@@ -602,12 +602,19 @@ int main(int argc, char **argv)
                if(sigaction(SIGTERM, &sa, NULL) == -1) {
                        error("Failed to change signal handler for SIGTERM");
                }
+
+               // save database on SIGUSR1
+               sa.sa_handler = sig_handler_save;
+               if(sigaction(SIGUSR1, &sa, NULL) == -1) {
+                       error("Failed to change signal handler for SIGUSR1");
+               }
+
                // Ignore SIGPIPE completely.
                // INFO: If we add signals here we have to unblock them
                // at popen.c when running a external plugin.
                sa.sa_handler = SIG_IGN;
                if(sigaction(SIGPIPE, &sa, NULL) == -1) {
-                       error("Failed to change signal handler for SIGTERM");
+                       error("Failed to change signal handler for SIGPIPE");
                }
 
                // --------------------------------------------------------------------
index 1c311d6a4fa81277e42d963b4a02f5cf17e3a2b0..483b9183623773052301b50d6f8c30c895d60f4c 100644 (file)
@@ -129,6 +129,10 @@ FILE *mypopen(const char *command, pid_t *pidptr)
                sigemptyset(&sa.sa_mask);
                sa.sa_handler = SIG_DFL;
                sa.sa_flags = 0;
+               
+               if(sigaction(SIGUSR1, &sa, NULL) == -1)
+                       error("pre-execution of command '%s' on pid %d: failed to set default signal handler for SIGUSR1.", command, getpid());
+
                if(sigaction(SIGPIPE, &sa, NULL) == -1)
                        error("pre-execution of command '%s' on pid %d: failed to set default signal handler for SIGPIPE.", command, getpid());
        }