Sophie

Sophie

distrib > Mageia > 5 > i586 > media > core-updates-src > by-pkgid > deecb6b6a05b8293e284be1ad9b5f073 > files > 18

xymon-4.3.17-5.1.mga5.src.rpm

From df85c08678b3e0f870b4d637f98e4634d70d2dfb Mon Sep 17 00:00:00 2001
From: William Murphy <warrendiogenese@gmail.com>
Date: Thu, 7 Aug 2014 22:31:00 -0700
Subject: [PATCH 1/2] Patched launchpid

---
 common/tasks.cfg.5                  |  7 ++++++-
 common/xymonlaunch.c                | 37 +++++++++++++++++++++++++++++++++++++
 docs/manpages/man5/tasks.cfg.5.html |  8 +++++++-
 3 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/common/tasks.cfg.5 b/common/tasks.cfg.5
index 768b99c..9d5526e 100644
--- a/common/tasks.cfg.5
+++ b/common/tasks.cfg.5
@@ -11,7 +11,7 @@ to perform all of the tasks needed by the Xymon monitor.
 
 .SH FILE FORMAT
 A task is defined by a \fBkey\fR, a \fBcommand\fR, and optionally 
-also \fBinterval\fR, \fBenvironment\fR, and \fBlogfile\fR.
+also \fBinterval\fR, \fBenvironment\fR, \fBlogfile\fR, and \fBpidfile\fR.
 
 Blank lines and lines starting with a hash mark (#) are treated as 
 comments and ignored.  Long lines can be broken up by putting a 
@@ -43,6 +43,8 @@ An entry looks like this:
           MAXTIME 10m
 .br
           LOGFILE /var/log/xymon/updateweb.log
+.br
+          PIDFILE /var/log/xymon/updateweb.pid
 .sp
     [monthlyreport]
 .br
@@ -133,6 +135,9 @@ xymonlaunch will start the task with stdout and stderr redirected
 to this file. If this option is not present, then the output
 goes to the same location as the xymonlaunch output.
 
+The \fBPIDFILE\fR setting defines a pidfile for the task.
+xymonlaunch will start the task and write the pid to this file. 
+
 .SH "SEE ALSO"
 xymonlaunch(8), xymond(8), crontab(5), xymon(7)
 
diff --git a/common/xymonlaunch.c b/common/xymonlaunch.c
index b3eb7de..41855cd 100644
--- a/common/xymonlaunch.c
+++ b/common/xymonlaunch.c
@@ -61,6 +61,7 @@ typedef struct tasklist_t {
 	char *cmd;
 	int interval, maxruntime;
 	char *logfile;
+	char *pidfile;
 	char *envfile, *envarea, *onhostptn;
 	pid_t pid;
 	time_t laststart;
@@ -131,6 +132,7 @@ void load_config(char *conffn)
 		twalk->maxruntime = 0;
 		twalk->group = NULL;
 		twalk->logfile = NULL;
+		twalk->pidfile = NULL;
 		twalk->envfile = NULL;
 		twalk->envarea = NULL;
 		twalk->onhostptn = NULL;
@@ -285,6 +287,11 @@ void load_config(char *conffn)
 			p += strspn(p, " \t");
 			xfreedup(curtask->logfile,p);
 		}
+		else if (curtask && (strncasecmp(p, "PIDFILE ", 8) == 0)) {
+			p += 7;
+			p += strspn(p, " \t");
+			xfreedup(curtask->pidfile,p);
+		}
 		else if (curtask && (strncasecmp(p, "NEEDS ", 6) == 0)) {
 			p += 6;
 			p += strspn(p, " \t");
@@ -337,6 +344,10 @@ void load_config(char *conffn)
 
 	/* Running tasks that have been deleted or changed are killed off now. */
 	for (twalk = taskhead; (twalk); twalk = twalk->next) {
+		/* old pidfn (if any) */
+		char *pidfn = NULL;
+		if (twalk->pidfile) pidfn = expand_env(twalk->pidfile);
+
 		/* compare the current settings with the copy - if we have one */
 		if (twalk->cfload == 0) {
 			if (twalk->copy) {
@@ -369,6 +380,7 @@ void load_config(char *conffn)
 				}
 				twalkstrcmp(cmd,1);
 				twalkstrcmp(logfile,1);
+				twalkstrcmp(pidfile,1);
 				twalkstrcmp(envfile,1);
 				twalkstrcmp(envarea,1);
 				twalkstrcmp(onhostptn,0);
@@ -400,10 +412,14 @@ void load_config(char *conffn)
 				twalk->beingkilled = 1;
 				kill(twalk->pid, SIGTERM);
 			}
+			/* Always remove pidfn, even if it wasn't running */
+			if (pidfn) unlink(pidfn);
+
 			/* And prepare to free this tasklist entry */
 			xfreenull(twalk->key); 
 			xfreenull(twalk->cmd); 
 			xfreenull(twalk->logfile);
+			xfreenull(twalk->pidfile);
 			xfreenull(twalk->envfile);
 			xfreenull(twalk->envarea);
 			xfreenull(twalk->onhostptn);
@@ -422,6 +438,9 @@ void load_config(char *conffn)
 				twalk->beingkilled = 1;
 				kill(twalk->pid, SIGTERM);
 			}
+			/* Always remove pidfn, even if it wasn't running */
+			if (pidfn) unlink(pidfn);
+
 			break;
 		}
 	}
@@ -574,6 +593,7 @@ int main(int argc, char *argv[])
 			if (twalk->cronstr)      printf("\tCRONDATE %s\n", twalk->cronstr);
 			if (twalk->maxruntime)   printf("\tMAXTIME %d\n", twalk->maxruntime);
 			if (twalk->logfile)      printf("\tLOGFILE %s\n", twalk->logfile);
+				if (twalk->pidfile)      printf("\tPIDFILE %s\n", twalk->pidfile);
 			if (twalk->envfile)      printf("\tENVFILE %s\n", twalk->envfile);
 			if (twalk->envarea)      printf("\tENVAREA %s\n", twalk->envarea);
 			if (twalk->onhostptn)    printf("\tONHOST %s\n", twalk->onhostptn);
@@ -749,6 +769,23 @@ int main(int argc, char *argv[])
 						reopen_file(logfn, "a", stderr);
 					}
 
+					/* Print our pid to a pidfile, if requested */
+					if (twalk->pidfile) {
+						char *pidfn = expand_env(twalk->pidfile);
+						FILE *pidfd = fopen(pidfn, "w");
+
+						dbgprintf("%s -> Writing PID to '%s'\n", twalk->key, pidfn);
+
+						if (pidfd) {
+							fprintf(pidfd, "%lu\n", (unsigned long)getpid());
+							fclose(pidfd);
+						}
+						else {
+							errprintf("Could not write PID to %s for command '%s': %s\n", 
+						   		pidfn, twalk->key, strerror(errno));
+						}
+					}
+
 					/* Go! */
 					dbgprintf("%s -> Running '%s', XYMONHOME=%s\n", twalk->key, cmd, xgetenv("XYMONHOME"));
 					execvp(cmd, cmdargs);
diff --git a/docs/manpages/man5/tasks.cfg.5.html b/docs/manpages/man5/tasks.cfg.5.html
index 51e7246..75e241f 100644
--- a/docs/manpages/man5/tasks.cfg.5.html
+++ b/docs/manpages/man5/tasks.cfg.5.html
@@ -27,7 +27,7 @@ to perform all of the tasks needed by the Xymon monitor.
 <H2>FILE FORMAT</H2>
 
 A task is defined by a <B>key</B>, a <B>command</B>, and optionally 
-also <B>interval</B>, <B>environment</B>, and <B>logfile</B>.
+also <B>interval</B>, <B>environment</B>, <B>logfile</B>, and <B>pidfile</B>.
 <P>
 Blank lines and lines starting with a hash mark (#) are treated as 
 comments and ignored.  Long lines can be broken up by putting a 
@@ -69,6 +69,9 @@ An entry looks like this:
 <BR>
 
 <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LOGFILE&nbsp;/var/log/xymon/updateweb.log
+<BR>
+
+<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PIDFILE&nbsp;/var/log/xymon/updateweb.pid
 <P>
 <BR>&nbsp;&nbsp;&nbsp;&nbsp;[monthlyreport]
 <BR>
@@ -164,6 +167,9 @@ xymonlaunch will start the task with stdout and stderr redirected
 to this file. If this option is not present, then the output
 goes to the same location as the xymonlaunch output.
 <P>
+The <B>PIDFILE</B> setting defines a pidfile for the task.
+xymonlaunch will start the task and write the PID to this file.
+<P>
 <A NAME="lbAF">&nbsp;</A>
 <H2>SEE ALSO</H2>
 
-- 
1.8.4.5


From 9e37e0d74b94d77d80681a109f06ff0fe41a522d Mon Sep 17 00:00:00 2001
From: William Murphy <warrendiogenese@gmail.com>
Date: Thu, 7 Aug 2014 22:31:00 -0700
Subject: [PATCH 2/2] Patched launchlogging

---
 client/clientlaunch.cfg.DIST   |  3 ++-
 xymond/etcfiles/tasks.cfg.DIST | 45 ++++++++++++++++++++++++++++--------------
 2 files changed, 32 insertions(+), 16 deletions(-)

diff --git a/client/clientlaunch.cfg.DIST b/client/clientlaunch.cfg.DIST
index 194f9cd..64ca926 100644
--- a/client/clientlaunch.cfg.DIST
+++ b/client/clientlaunch.cfg.DIST
@@ -16,8 +16,9 @@
 [msgcache]
 	DISABLED
 	ENVFILE $XYMONCLIENTHOME/etc/xymonclient.cfg
-	CMD $XYMONCLIENTHOME/bin/msgcache --no-daemon --pidfile=$XYMONCLIENTLOGS/msgcache.pid
+	CMD $XYMONCLIENTHOME/bin/msgcache --no-daemon
 	LOGFILE $XYMONCLIENTLOGS/msgcache.log
+	PIDFILE $XYMONCLIENTLOGS/msgcache.pid
 
 # The main client task
 [client]
diff --git a/xymond/etcfiles/tasks.cfg.DIST b/xymond/etcfiles/tasks.cfg.DIST
index 14eeb4e..565e2fa 100644
--- a/xymond/etcfiles/tasks.cfg.DIST
+++ b/xymond/etcfiles/tasks.cfg.DIST
@@ -18,41 +18,48 @@
 # you want to run).
 [xymond]
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
-	CMD xymond --pidfile=$XYMONSERVERLOGS/xymond.pid \
+	CMD xymond \
 		--restart=$XYMONTMP/xymond.chk --checkpoint-file=$XYMONTMP/xymond.chk --checkpoint-interval=600 \
-		--log=$XYMONSERVERLOGS/xymond.log \
 		--admin-senders=127.0.0.1,$XYMONSERVERIP \
 		--store-clientlogs=!msgs
+	LOGFILE $XYMONSERVERLOGS/xymond.log
+	PIDFILE $XYMONSERVERLOGS/xymond.pid
 
 # "history" keeps track of the status changes that happen.
 [history]
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=stachg --log=$XYMONSERVERLOGS/history.log xymond_history --pidfile=$XYMONSERVERLOGS/xymond_history.pid
+	CMD xymond_channel --channel=stachg xymond_history
+	LOGFILE $XYMONSERVERLOGS/history.log
+	PIDFILE $XYMONSERVERLOGS/xymond_history.pid
 
 # "alert" sends out alerts.
 [alert]
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=page  --log=$XYMONSERVERLOGS/alert.log xymond_alert --checkpoint-file=$XYMONTMP/alert.chk --checkpoint-interval=600
+	CMD xymond_channel --channel=page xymond_alert --checkpoint-file=$XYMONTMP/alert.chk --checkpoint-interval=600
+	LOGFILE $XYMONSERVERLOGS/alert.log
 
 # The client back-end module. You need this if you are running the Xymon client on any system.
 [clientdata]
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=client --log=$XYMONSERVERLOGS/clientdata.log xymond_client
+	CMD xymond_channel --channel=client xymond_client
+	LOGFILE $XYMONSERVERLOGS/clientdata.log
 
 # "rrdstatus" updates RRD files with information that arrives as "status" messages.
 [rrdstatus]
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=status --log=$XYMONSERVERLOGS/rrd-status.log xymond_rrd --rrddir=$XYMONVAR/rrd
+	CMD xymond_channel --channel=status xymond_rrd --rrddir=$XYMONVAR/rrd
+	LOGFILE $XYMONSERVERLOGS/rrd-status.log
 
 # "rrddata" updates RRD files with information that arrives as "data" messages.
 [rrddata]
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=data   --log=$XYMONSERVERLOGS/rrd-data.log xymond_rrd --rrddir=$XYMONVAR/rrd
+	CMD xymond_channel --channel=data xymond_rrd --rrddir=$XYMONVAR/rrd
+	LOGFILE $XYMONSERVERLOGS/rrd-data.log
 
 # "hostdata" stores the Xymon client messages on disk when some status for a host
 # changes. This lets you access a lot of data collected from a host around the time
@@ -63,7 +70,8 @@
 [hostdata]
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=clichg --log=$XYMONSERVERLOGS/hostdata.log xymond_hostdata
+	CMD xymond_channel --channel=clichg xymond_hostdata
+	LOGFILE $XYMONSERVERLOGS/hostdata.log
 
 # "distribute" forwards enable/disable/drop/rename messages to other Xymon servers.
 # You would use it when running Xymon in an active/passive (master/slave) configuration.
@@ -77,7 +85,8 @@
 	DISABLED
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=enadis --log=$XYMONSERVERLOGS/distribute.log xymond_distribute --peer=IP.OF.SLAVE.SERVER
+	CMD xymond_channel --channel=enadis xymond_distribute --peer=IP.OF.SLAVE.SERVER
+	LOGFILE $XYMONSERVERLOGS/distribute.log
 
 
 ######################################################################################
@@ -100,8 +109,9 @@
 [xymonproxy]
 	DISABLED
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
-	CMD $XYMONHOME/bin/xymonproxy --server=YOUR.XYMON.SERVER.IP --report=$MACHINE.xymonproxy --no-daemon --pidfile=$XYMONSERVERLOGS/xymonproxy.pid
+	CMD $XYMONHOME/bin/xymonproxy --server=YOUR.XYMON.SERVER.IP --report=$MACHINE.xymonproxy --no-daemon
 	LOGFILE $XYMONSERVERLOGS/xymonproxy.log
+	PIDFILE $XYMONSERVERLOGS/xymonproxy.pid
 
 
 # "xymonfetch" is used when you have clients that cannot connect to your Xymon server,
@@ -115,8 +125,9 @@
 [xymonfetch]
 	DISABLED
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
-	CMD $XYMONHOME/bin/xymonfetch --server=YOUR.XYMON.SERVER.IP --no-daemon --pidfile=$XYMONSERVERLOGS/xymonfetch.pid
+	CMD $XYMONHOME/bin/xymonfetch --server=YOUR.XYMON.SERVER.IP --no-daemon
 	LOGFILE $XYMONSERVERLOGS/xymonfetch.log
+	PIDFILE $XYMONSERVERLOGS/xymonfetch.pid
 
 
 ######################################################################################
@@ -225,7 +236,8 @@ include @XYMONTOPDIR@/client/etc/clientlaunch.cfg
 	DISABLED
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=status --log=$XYMONSERVERLOGS/status.log xymond_filestore --status --html
+	CMD xymond_channel --channel=status xymond_filestore --status --html
+	LOGFILE $XYMONSERVERLOGS/status.log
 
 # "storedata" saves information sent using the BB "data" protocol, like the old Big Brother 
 # daemon does. Unless you are using add-ons that directly access the data-files, you 
@@ -237,7 +249,8 @@ include @XYMONTOPDIR@/client/etc/clientlaunch.cfg
 	DISABLED
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=data   --log=$XYMONSERVERLOGS/data.log xymond_filestore --data
+	CMD xymond_channel --channel=data xymond_filestore --data
+	LOGFILE $XYMONSERVERLOGS/data.log
 
 # "storeenadis" updates the files used to indicate that a host or test has been enabled or disabled.
 # Unless you are running server side scripts that look at these files, you do not need this.
@@ -245,7 +258,8 @@ include @XYMONTOPDIR@/client/etc/clientlaunch.cfg
 	DISABLED
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=enadis --log=$XYMONSERVERLOGS/enadis.log xymond_filestore --enadis
+	CMD xymond_channel --channel=enadis xymond_filestore --enadis
+	LOGFILE $XYMONSERVERLOGS/enadis.log
 
 # "storenotes" saves web note-files, that are sent using the BB "notes" protocol. This is
 # disabled by default; if you use the Big Brother "notes" protocol, then you should enable this.
@@ -253,7 +267,8 @@ include @XYMONTOPDIR@/client/etc/clientlaunch.cfg
 	DISABLED
 	ENVFILE @XYMONHOME@/etc/xymonserver.cfg
 	NEEDS xymond
-	CMD xymond_channel --channel=notes  --log=$XYMONSERVERLOGS/notes.log xymond_filestore --notes
+	CMD xymond_channel --channel=notes xymond_filestore --notes
+	LOGFILE $XYMONSERVERLOGS/notes.log
 
 
 
-- 
1.8.4.5