[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
configuration patch - final version
From: |
Martin Pala |
Subject: |
configuration patch - final version |
Date: |
Tue, 11 Feb 2003 18:18:35 +0100 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021226 Debian/1.2.1-9 |
There's final version of the patch, it implements:
1.) let monit reload only on SIGHUP
2.) new monit command 'reload' added - it will cause monit's
reinitialization (send SIGHUP to running daemon)
3.) new monit option '-t' added - instructs monit to run in testing mode
(just parse configuration and exit). Any error is reported by parser,
otherwise success is signalized on terminal.
Martin
P.S. sorry for loading the list by so many patches - i remembered that
we decided to add 'reload' command and '-t' option too after i send
first patch
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 18:12:14.000000000 +0100
@@ -4,6 +4,16 @@
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.
+
+* New monit command 'reload' was added. If used, it will reinitialize
+ running monit daemon (send it the SIGHUP signal).
+
+* New monit option '-t' was added. If used, monit will check control
+ file syntax and exit with the status.
+
* 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 17:39:19.000000000 +0100
@@ -70,7 +70,6 @@
void daemonize() {
pid_t pid;
- void *hup_handler= NULL;
/*
* Clear file creation mask
@@ -94,11 +93,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");
@@ -129,28 +123,23 @@
*/
redirect_stdfd();
- /*
- * Reset the SIGHUP handler
- */
- if(hup_handler)
- signal(SIGHUP, hup_handler);
-
}
/**
- * Kill a daemon process
- * @return TRUE if the daemon was killed, otherwise FALSE
+ * Send signal to a daemon process
+ * @param sig Signal to send daemon to
+ * @return TRUE if signal was send, otherwise FALSE
*/
-int kill_daemon() {
+int kill_daemon(int sig) {
pid_t pid;
if ( (pid= exist_daemon()) > 0 ) {
- if ( kill(pid, SIGTERM) < 0 ) {
+ if ( kill(pid, sig) < 0 ) {
- error("%s: Cannot kill daemon process -- %s\n",prog, STRERROR);
+ error("%s: Cannot send signal to daemon process -- %s\n",prog, STRERROR);
return FALSE;
}
@@ -162,8 +151,12 @@
}
- fprintf(stdout, "%s daemon with pid [%d] killed\n", prog, (int)pid);
- fflush(stdout);
+ if(sig == SIGTERM) {
+
+ fprintf(stdout, "%s daemon with pid [%d] killed\n", prog, (int)pid);
+ fflush(stdout);
+
+ }
return TRUE;
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 17:47:06.000000000 +0100
@@ -113,8 +113,6 @@
}
- Run.timestamp= get_timestamp(Run.controlfile, S_IFREG);
-
}
@@ -237,18 +235,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/monit.pod monit-sighup/monit.pod
--- monit/monit.pod 2003-02-11 13:39:07.000000000 +0100
+++ monit-sighup/monit.pod 2003-02-11 18:06:52.000000000 +0100
@@ -40,20 +40,26 @@
B<-c> I<file>
Use this control file
+B<-d> I<n>
+ Run as a daemon once per I<n> seconds
+
+B<-g>
+ Set group name for start, stop, restart and status
+
B<-l> I<logfile>
- Print log information to this file.
+ Print log information to this file
B<-p> I<pidfile>
- Use this lock file in daemon mode.
+ Use this lock file in daemon mode
-B<-d> I<n>
- Run as a daemon once per I<n> seconds
+B<-i>
+ Validate mode, startup in validate mode
B<-I>
Run from init (do not run in background)
-B<-g>
- Set group name for start, stop, restart and status
+B<-t>
+ Configuration syntax testing mode
B<-v>
Verbose mode, work noisy (diagnostic output)
@@ -89,6 +95,11 @@
monitrc file, after a I<check> keyword. See also
the MONIT HTTPD section below.
+B<reload>
+ Will reinitialize running monit daemon, specifically
+ it will reread its configuration, close and reopen
+ log files.
+
B<restart>
Stop and start all programs. If the group option is
set, only restart the programs in the named group.
@@ -156,13 +167,6 @@
The I<quit> argument will kill a running daemon process instead
of waking it up.
-If you touch or change the I<.monitrc> file while monit is
-running in daemon mode, this will be detected at the beginning of
-the next poll cycle. When a changed I<.monitrc> is detected,
-monit rereads it and reinitialize itself. Note also that if you
-break the I<.monitrc> file's syntax, the monit daemon will exit
-after logging the appropriate error message.
-
=head2 monit lock file
@@ -1548,9 +1552,11 @@
If a monit daemon is running, SIGUSR1 wakes it up from its sleep
phase and forces a poll of all processes. SIGTERM will gracefully
terminate a monit daemon. This signal is sent to a monit daemon
-if monit is started with the I<quit> action argument. Sending a
-SIGHUP signal to a running monit daemon will force the daemon to
-reload itself, specifically it will close and reopen log files.
+if monit is started with the I<quit> action argument.
+
+Sending a SIGHUP signal to a running monit daemon will force
+the daemon to reinitialize itself, specifically it will reread
+configuration, close and reopen log files.
Running monit in foreground while a background monit daemon is
running will wake up the daemon.
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 18:00:38.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,
@@ -176,6 +175,13 @@
}
+ if(Run.testing) {
+
+ error("Configuration syntax test passed\n");
+ exit(1);
+
+ }
+
/*
* Initialize the log system
*/
@@ -218,9 +224,18 @@
* the runtime control file was changed during daemon
* mode.
*/
-static void do_reinit() {
+static RETSIGTYPE do_reinit(int sig) {
+
+ char *bind_addr;
+ int port= Run.httpdport;
- log("Reinitializing %s - Control file '%s' was changed\n",
+
+ 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 +278,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);
+
}
@@ -310,6 +344,11 @@
control("stop");
}
+ } else if(is(action, "reload")) {
+
+ error("Reinitializing monit daemon\n", prog);
+ kill_daemon(SIGHUP);
+
} else if(is(action, "restart")) {
if(P) {
@@ -348,7 +387,7 @@
} else if(is(action, "quit")) {
error("Stopping monit daemon\n", prog);
- kill_daemon();
+ kill_daemon(SIGTERM);
} else if(is(action, "validate")) {
@@ -380,21 +419,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 +521,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);
-
- }
-
-
}
}
@@ -548,7 +545,7 @@
Run.mygroup=0;
- while((opt= getopt(argc,argv,"c:d:g:l:p:iIvVh")) != -1) {
+ while((opt= getopt(argc,argv,"c:d:g:l:p:iItvVh")) != -1) {
switch(opt) {
@@ -588,6 +585,10 @@
Run.init= TRUE;
break;
+ case 't':
+ Run.testing= TRUE;
+ break;
+
case 'v':
Run.debug= TRUE;
break;
@@ -641,6 +642,7 @@
printf(" -p pidfile Use this lock file in daemon mode\n");
printf(" -i Validate mode, startup in validate mode\n");
printf(" -I Init mode, run from init\n");
+ printf(" -t Configuration syntax testing mode\n");
printf(" -v Verbose mode, work noisy (diagnostic output)\n");
printf(" -V Print version number and patchlevel\n");
printf(" -h Print this text\n");
@@ -649,6 +651,7 @@
printf(" start name - Only start the named program in the control file\n");
printf(" stop - Stop all programs listed in the control file\n");
printf(" stop name - Only stop the named program in the control file\n");
+ printf(" reload - Reinitialize monit\n");
printf(" restart - Stop and start all programs\n");
printf(" restart name - Only restart the named program in the control
file\n");
printf(" status - Print status information for each program\n");
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 17:54:05.000000000 +0100
@@ -138,7 +138,7 @@
int doprocess; /**< TRUE if process status engine is used */
char *bind_addr; /**< The address monit http will bind to */
mode_t umask; /**< The initial umask monit was started with */
- time_t timestamp; /**< Control file last modified timestamp */
+ int testing; /**< Running in configuration testing mode - TRUE or FALSE */
double loadavg[3]; /**< Load average triple */
@@ -376,9 +376,8 @@
void finalize_files();
char *find_rcfile();
int create_pidfile(char *);
-int is_rcfile_changed();
int check_rcfile(char *);
-int kill_daemon();
+int kill_daemon(int);
int exist_daemon();
void sendmail(Mail_T);
int sock_msg(int sock, char *, ...);
- configuration patch - final version,
Martin Pala <=
- RE: configuration patch - final version, Jan-Henrik Haukeland, 2003/02/11
- Re: configuration patch - final version, Martin Pala, 2003/02/11
- RE: configuration patch - final version, Jan-Henrik Haukeland, 2003/02/11
- RE: configuration patch - final version, Christian Hopp, 2003/02/11
- RE: configuration patch - final version, Jan-Henrik Haukeland, 2003/02/11
- Re: configuration patch - final version, Martin Pala, 2003/02/11
- RE: configuration patch - final version, Jan-Henrik Haukeland, 2003/02/12
- RE: configuration patch - final version, Christian Hopp, 2003/02/12
- Re: configuration patch - final version, Jan-Henrik Haukeland, 2003/02/12
- Re: configuration patch - final version, Martin Pala, 2003/02/11