[Mimedefang] monitor scripts for mimedefang/sendmail
Rick Mallett
rmallett at ccs.carleton.ca
Tue Feb 3 14:46:13 EST 2004
Here's one that's untested and unused. Actually, I did do some
testing, and I think its pretty good, but we stopped having problems
with mimedefang dying before I could get it into use, and I simply
haven't had time to install it. Call it restart-mimedefang.c and
compile (on Solaris) using
gcc -o restart-mimedefang restart-mimedefang.c -lgen
#include <stdio.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <regexpr.h>
#define PROBLEM "Connection refused by /var/spool/MIMEDefang/mimedefang.sock$"
main (int argc, char *argv[])
{
FILE *f;
char *exp;
pid_t pid;
int wstatus;
char *args[2];
char buffer [1024];
char mailfile[] = "/var/adm/mail";
if ((f = fopen (mailfile, "r")) == NULL) {
fprintf (stderr, "Unable to open file %s\n",mailfile);
exit (1);
}
if ((exp = compile(PROBLEM, (char *)0, (char *)0)) == (char *)0) {
fprintf(stderr, "Failed to compile regular expression.\n");
exit(1);
}
args[0] = "restart-mimedefang";
args[1] = (char *)0;
fseek(f, SEEK_END, 0L);
while (1) {
sleep (5);
if (-1 == fseek (f, SEEK_CUR, 1)) {
fprintf (stderr, "Unexpected fseek failure.\n");
exit (1);
}
fgets (buffer, 1024, f);
while (!feof(f)) {
buffer [strlen (buffer) - 1] = 0;
if (step(buffer,exp)) {
pid = fork();
switch (pid) {
case -1:
fprintf(stderr, "System failure - unable to fork a process.\n");
exit(1);
case 0: /* child */
execv("/usr/local/bin/restart-mimedefang", args);
fprintf(stderr, "System failure - unexpected return from execv.\n");
exit(1);
default: /* parent */
waitpid(pid, &wstatus, 0); /* wait for child */
if(WEXITSTATUS(wstatus) != 0 || WTERMSIG(wstatus) > 0) { /* error return */
fprintf(stderr, "System failure - wait exit status %d.\n",wstatus);
exit(1);
}
}
}
fgets (buffer, 1024, f);
}
}
}
- rick
On Tue, 3 Feb 2004, Lucas Albers wrote:
> I would be interested in any swatch scripts or other monitor scripts
> people use to watch mimedefang/sendmail and restart it if it dies.
> I currently do not use a log monitor script to determine when
> mimedefang/sendmail dies.
> I use the monit program which just tells me that the program is accepting
> connections, and the process is running.
> I would like to configure a finer grained monitor of mimedefang/sendmail
> so I can restart them when they have problems.
> Or at least get emailed.
>
> I'm considering all I need to do is swatch the log for milter timeout or
> similar, and then do a restart.
> By why invent the wheel when someone else already has...
>
>
> Luke Computer Science System Administrator
>
> _______________________________________________
> Visit http://www.mimedefang.org and http://www.canit.ca
> MIMEDefang mailing list
> MIMEDefang at lists.roaringpenguin.com
> http://lists.roaringpenguin.com/mailman/listinfo/mimedefang
>
More information about the MIMEDefang
mailing list