[Mimedefang] Re: Mimedefang daemons won't stop
David F. Skoll
dfs at roaringpenguin.com
Wed Mar 26 09:05:56 EST 2003
On Wed, 26 Mar 2003, Michael Sims wrote:
> I'm stumped. Maybe David or someone else on the list has an idea.
> You could throw some debug lines inside /etc/rc.d/init.d/mimedefang
The problem may be that Red Hat's killproc() function expects to find
a pid file in /var/run; MIMEDefang keeps its pid files in
/var/spool/MIMEDefang.
I do not use the Red Hat init script on my Red Hat box. Here
is an edited version of the init script I use for our commercial CanIt
product; it seems to work on all the UNIXes we support. Be sure
to create /etc/sysconfig/mimedefang and set all the variables
(see redhat/mimedefang-sysconfig in the distribution.)
If it works well for you, I'll make it the "official" init script.
Regards,
David.
# ------------------- CUT HERE ---------------------------------------------
#!/bin/sh
#
# mimedefang This shell script takes care of starting and stopping mimedefang
#
# chkconfig: 2345 86 14
# description: MIMEDefang is a mail filter
##########################################################################
# Copyright 2002-2003, Roaring Penguin Software Inc. All rights reserved.
#
# Current Revision:
#
# $Source: /home/cvs/CanIt/scripts/mimedefang-ctrl,v $
# $Revision: 1.15 $
# $Author: dfs $
# $Date: 2003/02/10 18:53:24 $
#
##########################################################################
# Perl 5.8 on Linux doesn't like other locales
LANG=C
export LANG
# Generic start/stop script for MIMEDefang. Should work on most
# flavors of UNIX.
RETVAL=0
prog='mimedefang'
SPOOLDIR='/var/spool/MIMEDefang'
PID="$SPOOLDIR/$prog.pid"
MXPID="$SPOOLDIR/$prog-multiplexor.pid"
# Is the program executable? We search in /usr/bin and /usr/local/bin.
if [ -x /usr/local/bin/$prog ] ; then
PROGDIR=/usr/local/bin
elif [ -x /usr/bin/$prog ] ; then
PROGDIR=/usr/bin
elif [ -x /usr/local/bin/$prog ] ; then
PROGDIR=/usr/local/bin
else
exit 0
fi
# Source configuration
if [ -f /etc/sysconfig/$prog ] ; then
. /etc/sysconfig/$prog
else
echo "/etc/sysconfig/$prog not found... please create it."
exit 1
fi
# Make sure reqired vars are set
SOCKET=${SOCKET:=$SPOOLDIR/$prog.sock}
MX_SOCKET=${MX_SOCKET:=$SPOOLDIR/$prog-multiplexor.sock}
start() {
if test -r $PID ; then
if kill -0 `cat $PID` > /dev/null 2>&1 ; then
echo "mimedefang (`cat $PID`) seems to be running."
return 1
fi
fi
if test "$MULTIPLEXOR" = "yes" -a -r $MXPID ; then
if kill -0 `cat $MXPID` > /dev/null 2>&1 ; then
echo "mimedefang-multiplexor (`cat $MXPID`) seems to be running."
return 1
fi
fi
printf "%-60s" "Validating setup: "
$PROGDIR/mimedefang.pl `[ -n "$SUBFILTER" ] && echo "-f $SUBFILTER"` -validate
if test "$?" = "0" ; then
echo "[ OK ]"
else
echo "[FAILED]"
return 1
fi
if [ "$MULTIPLEXOR" = "yes" ]; then
printf "%-60s" "Starting $prog-multiplexor: "
rm -f $MX_SOCKET > /dev/null 2>&1
$PROGDIR/$prog-multiplexor -p $MXPID \
`[ -n "$FILTER" ] && echo "-f $FILTER"` \
`[ -n "$SUBFILTER" ] && echo "-F $SUBFILTER"` \
`[ -n "$MX_MINIMUM" ] && echo "-m $MX_MINIMUM"` \
`[ -n "$MX_MAXIMUM" ] && echo "-x $MX_MAXIMUM"` \
`[ -n "$MX_USER" ] && echo "-U $MX_USER"` \
`[ -n "$MX_IDLE" ] && echo "-i $MX_IDLE"` \
`[ -n "$MX_BUSY" ] && echo "-b $MX_BUSY"` \
`[ -n "$MX_CMD_TIMEOUT" ] && echo "-c $MX_CMD_TIMEOUT"` \
`[ -n "$MX_REQUESTS" ] && echo "-r $MX_REQUESTS"` \
`[ -n "$MX_SLAVE_DELAY" ] && echo "-w $MX_SLAVE_DELAY"` \
`[ -n "$MX_MIN_SLAVE_DELAY" ] && echo "-W $MX_MIN_SLAVE_DELAY"` \
`[ -n "$MX_MAX_RSS" ] && echo "-R $MX_MAX_RSS"` \
`[ -n "$MX_MAX_AS" ] && echo "-M $MX_MAX_AS"` \
`[ "$MX_LOG" = "yes" ] && echo "-l"` \
`[ "$MX_STATS" = "yes" ] && echo "-t /var/log/mimedefang/stats"` \
`[ "$MX_STATS" = "yes" -a "$MX_FLUSH_STATS" = "yes" ] && echo "-u"` \
`[ "$MX_STATS_SYSLOG" = "yes" ] && echo "-T"` \
-s $MX_SOCKET
RETVAL=$?
if [ $RETVAL = 0 ] ; then
echo "[ OK ]"
else
echo "[FAILED]"
return 1
fi
fi
# Start mimedefang
printf "%-60s" "Starting $prog: "
rm -f $SOCKET > /dev/null 2>&1
$PROGDIR/$prog -P $PID \
`[ -n "$MX_USER" ] && echo "-U $MX_USER"` \
`[ "$MULTIPLEXOR" != "yes" -a -n "$FILTER" ] && echo "-f $FILTER"` \
`[ "$MULTIPLEXOR" != "yes" -a -n "$SUBFILTER" ] && echo "-F $SUBFILTER"` \
`[ "$MULTIPLEXOR" != "yes" -a -n "$MAXIMUM" ] && echo "-n $MAXIMUM"` \
`[ "$MULTIPLEXOR" = "yes" ] && echo "-m $MX_SOCKET"` \
`[ "$MULTIPLEXOR" = "yes" -a "$MX_RELAY_CHECK" = "yes" ] && echo "-r"` \
`[ "$MULTIPLEXOR" = "yes" -a "$MX_SENDER_CHECK" = "yes" ] && echo "-s"` \
`[ "$MULTIPLEXOR" = "yes" -a "$MX_RECIPIENT_CHECK" = "yes" ] && echo "-t"` \
`[ "$KEEP_FAILED_DIRECTORIES" = "yes" ] && echo "-k"` \
`[ "$LOG_TIMES_TO_SYSLOG" = "yes" ] && echo "-T"` \
`[ "$USE_MKDIR_MUTEX" = "yes" ] && echo "-M"` \
-p $SOCKET -x "CanIt (www . canit . ca)"
RETVAL=$?
if [ $RETVAL = 0 ] ; then
echo "[ OK ]"
else
echo "[FAILED]"
kill `cat $MXPID`
return 1
fi
return 0
}
status() {
RETVAL=0
# Check status of MIMEDefang
if test -f "$PID" ; then
X=`cat $PID`
kill -0 $X > /dev/null 2>&1
if test "$?" = 0 ; then
echo "mimedefang is running (pid $X)"
else
echo "mimedefang is stopped (pid $X)"
RETVAL=1
fi
else
echo "mimedefang is stopped"
RETVAL=1
fi
if [ "$MULTIPLEXOR" = "yes" ] ; then
if test -f "$MXPID" ; then
X=`cat $MXPID`
kill -0 $X > /dev/null 2>&1
if test "$?" = 0 ; then
echo "mimedefang-multiplexor is running (pid $X)"
else
echo "mimedefang-multiplexor is stopped (pid $X)"
RETVAL=1
fi
else
echo "mimedefang-multiplexor is stopped"
RETVAL=1
fi
fi
return $RETVAL
}
stop() {
# Stop daemon
printf "%-60s" "Shutting down $prog: "
if test -f "$PID" ; then
# Yikes! Sorry to do kill -9, but libmilter seems to
# catch SIGINT nowadays...
kill -9 `cat $PID`
RETVAL=$?
else
RETVAL=1
fi
if [ $RETVAL = 0 ] ; then
echo "[ OK ]"
else
echo "[FAILED]"
fi
rm -f $SOCKET > /dev/null 2>&1
rm -f $PID > /dev/null 2>&1
if [ "$MULTIPLEXOR" = "yes" ]; then
# Stop daemon
printf "%-60s" "Shutting down $prog-multiplexor: "
if test -f "$MXPID" ; then
kill `cat $MXPID`
RETVAL=$?
else
RETVAL=1
fi
if [ $RETVAL = 0 ] ; then
echo "[ OK ]"
else
echo "[FAILED]"
fi
rm -f $MX_SOCKET > /dev/null 2>&1
rm -f $MXPID > /dev/null 2>&1
fi
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
start
RETVAL=$?
;;
status)
status
RETVAL=$?
;;
reread|reload)
if [ "$MULTIPLEXOR" != "yes" ]; then
exit 0
fi
if [ -r $MXPID ] ; then
kill -INT `cat $MXPID`
RETVAL=$?
if [ $RETVAL = 0 ] ; then
echo "Told $prog-multiplexor to force reread of filter rules."
else
echo "Could not signal $prog-multiplexor"
fi
else
RETVAL=1
echo "Could not find process-ID of $prog-multiplexor"
fi
;;
*)
echo "Usage: $0 {start|stop|restart|reread|reload|status}"
exit 1
esac
exit $RETVAL
More information about the MIMEDefang
mailing list