monit-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: patch for SIGHUP reinitialization


From: Martin Pala
Subject: Re: patch for SIGHUP reinitialization
Date: Tue, 11 Feb 2003 16:57:18 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021226 Debian/1.2.1-9

Pretty patch - im sorry (forgotten attachment :)

Martin Pala wrote:

Hi,

there's patch to make monit reload configuration only on SIGHUP signal.

It simplifies present SIGHUP handling implementation as well.

Its OK to check it in?

Martin



_______________________________________________
monit-dev mailing list
address@hidden
http://mail.nongnu.org/mailman/listinfo/monit-dev


diff -Naur monit/CHANGES.txt monit-sighup/CHANGES.txt
--- monit/CHANGES.txt   2003-02-11 14:51:58.000000000 +0100
+++ monit-sighup/CHANGES.txt    2003-02-11 16:55:43.000000000 +0100
@@ -4,6 +4,10 @@
 
 Version 3.2
 
+*  Monit now reloads configuration ONLY after it receives SIGHUP.
+   Automatic reload based on monit's control file timestamp change
+   is now deprecated.
+
 *  The ssl version for TCPSSL test can be changed in case autodetection 
    fails. (Thanks to Mark Foster <address@hidden> for the bugreport)
 
diff -Naur monit/daemonize.c monit-sighup/daemonize.c
--- monit/daemonize.c   2003-02-09 19:25:28.000000000 +0100
+++ monit-sighup/daemonize.c    2003-02-11 16:18:41.000000000 +0100
@@ -94,11 +94,6 @@
   
   setsid();
 
-  /*
-   * Don't let future opens allocate controlling terminals
-   */
-  hup_handler= signal(SIGHUP, SIG_IGN);
-
   if((pid= fork ()) < 0) {
     
     log("Cannot fork of a new process\n");  
diff -Naur monit/files.c monit-sighup/files.c
--- monit/files.c       2003-01-11 10:04:49.000000000 +0100
+++ monit-sighup/files.c        2003-02-11 16:42:02.000000000 +0100
@@ -237,18 +237,6 @@
 
 
 /**
- * Test the monit control file for changes.
- * @return TRUE if the Runtime control file was changed,
- * otherwise FALSE
- */
-int is_rcfile_changed() {
-  
-  return(get_timestamp(Run.controlfile, S_IFREG) != Run.timestamp);
-  
-}
-
-
-/**
  * Secure check the monitrc file. The run control file must have the
  * same uid as the REAL uid of this process, it must have permissions
  * no greater than 700 and it must not be a symbolic link.  We check
diff -Naur monit/monitor.c monit-sighup/monitor.c
--- monit/monitor.c     2003-02-10 01:09:19.000000000 +0100
+++ monit-sighup/monitor.c      2003-02-11 16:49:26.000000000 +0100
@@ -69,13 +69,12 @@
 
 /* --- Private Prototypes -------------------------------------------------- */
 static void  do_init();                       /* Initialize this application */
-static void  do_reinit();           /* Re-initialize the runtime application */
+static RETSIGTYPE  do_reinit(int);  /* Re-initialize the runtime application */
 static void  do_action(char **);         /* Dispatch to the submitted action */
 static RETSIGTYPE  do_destroy(int);             /* Finalize this application */
 static void  do_default();                              /* Do default action */
 static RETSIGTYPE  do_wakeup(int); /* Signalhandler for a daemon wakeup call */
 static int   do_wakeupcall();              /* Wakeup a sleeping monit daemon */
-static RETSIGTYPE do_restart(int sig);   /* Signalhandler for daemon restart */
 static void  handle_options(int, char **);         /* Handle program options */
 static void  help();                 /* Print program help message to stdout */
 static void  version();                         /* Print version information */
@@ -130,9 +129,9 @@
   /*
    * Register interest for the SIGHUP signal,
    * in case we run in daemon mode this signal
-   * will restart the monit daemon.
+   * will reload the configuration.
    */
-  signal(SIGHUP, do_restart);
+  signal(SIGHUP, do_reinit);
 
   /*
    * Register no interest for the SIGPIPE signal,
@@ -218,9 +217,18 @@
  * the runtime control file was changed during daemon
  * mode.
  */
-static void do_reinit() {
+static RETSIGTYPE do_reinit(int sig) {
 
-  log("Reinitializing %s - Control file '%s' was changed\n",
+  char *bind_addr;
+  int port= Run.httpdport;
+
+
+  signal(SIGHUP, SIG_IGN);
+
+  bind_addr= Run.bind_addr?xstrdup(Run.bind_addr):NULL;
+
+  log("Awakened by the SIGHUP signal\n");
+  log("Reinitializing %s - Control file '%s'\n",
       prog, Run.controlfile);
   
   /* Run the garbage collector */
@@ -263,6 +271,25 @@
       
   }
 
+  if(! can_http()) {
+         
+    stop_http();
+         
+  } else if(!is(bind_addr, Run.bind_addr) || port != Run.httpdport) {
+         
+    stop_http();
+    start_http();
+         
+  } else if(! check_httpd()) {
+
+    start_http();
+         
+  }
+
+  free(bind_addr);
+
+  signal(SIGHUP, do_reinit);
+
 }
 
 
@@ -380,21 +407,6 @@
 
 
 /**
- * Signalhandler for a daemon restart call. The timestamp of the
- * control file is changed with the effect that a monit daemon will
- * restart itself, including closing and reopening log files.
- */
-static RETSIGTYPE do_restart(int sig) {
-
-  signal(SIGHUP, SIG_IGN);
-  Run.timestamp= 0;
-  log("Awakened by the SIGHUP signal\n");
-  signal(SIGHUP, do_restart);
-
-}
-
-
-/**
  * Wakeup a sleeping monit daemon.
  * Returns TRUE on success otherwise FALSE
  */
@@ -497,33 +509,6 @@
 
       sleep(Run.polltime);
 
-      if(is_rcfile_changed()) {
-       
-       int port= Run.httpdport;
-       char *bind_addr= Run.bind_addr?xstrdup(Run.bind_addr):NULL;
-
-       do_reinit();
-       
-       if(! can_http()) {
-         
-         stop_http();
-         
-       } else if(!is(bind_addr, Run.bind_addr) || port != Run.httpdport) {
-         
-         stop_http();
-         start_http();
-         
-       } else if(! check_httpd()) {
-
-         start_http();
-         
-       }
-
-       free(bind_addr);
-       
-      }
-     
-
     }
     
   }
diff -Naur monit/monitor.h monit-sighup/monitor.h
--- monit/monitor.h     2003-02-10 19:52:43.000000000 +0100
+++ monit-sighup/monitor.h      2003-02-11 16:42:17.000000000 +0100
@@ -376,7 +376,6 @@
 void  finalize_files();
 char *find_rcfile();    
 int   create_pidfile(char *);
-int   is_rcfile_changed();
 int   check_rcfile(char *);
 int   kill_daemon();
 int   exist_daemon(); 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]