#!/bin/bash ########################################################################## # Copyright @2002, Roaring Penguin Software Inc. All rights reserved. # # Project : MIMEDefang # Component : redhat/mimedefang-init # Author : Michael McLagan # Creation : 30-Apr-2002 13:42 # Description : This is the init script for the RedHat RPM. It lives # in /etc/rc.d/init.d as mimedefang and is called by # init during system startup. # # Uses redhat/mimedefang-sysconfig (/etc/sysconfig/mimedefang) # to set various variables used as parameters to start the # mimedefang and mimedefang-multiplexor daemons. # # Based on init scripts provided by RedHat and others. # # mimedefang should be started before sendmail and stopped # after sendmail. The values in the chkconfig: line below # are based on those in the default (RedHat issued) sendmail # script as /etc/rc.d/init.d/sendmail (80 30) # # Current Revision: # # $Source: /home/cvsroot/MIMEDefang/redhat/mimedefang-init.in,v $ # $Revision: 1.11 $ # $Author: dfs $ # $Date: 2004/10/28 20:31:21 $ # # Revision History: # # $Log: mimedefang-init.in,v $ # Revision 1.11 2004/10/28 20:31:21 dfs # Add MX_STATUS_UPDATES variable to shell script. # # Revision 1.10 2004/10/28 15:56:18 dfs # Fixed RH init script to always run ulimit -s # # Revision 1.9 2004/06/21 18:46:03 dfs # Add MX_MAP_SOCKET variable in init scripts. # # Revision 1.8 2004/06/08 02:18:08 dfs # Wait for daemons to exit. # # Revision 1.7 2004/03/30 21:33:33 dfs # Minor fixes. # # Revision 1.6 2004/03/30 21:32:19 dfs # Fixed typo. # # Revision 1.5 2004/03/30 21:25:34 dfs # Improved MIMEDefang init scripts. # # Revision 1.4 2004/02/23 16:43:23 dfs # Added MX_NOTIFIER option in sysconfig and init script. # # Revision 1.3 2003/11/10 15:52:56 dfs # Fixe for "echo -E" issue. # # Revision 1.2 2003/11/10 14:57:16 dfs # Added MX_EMBED_PERL parameter. # # Revision 1.1 2003/07/23 18:27:35 dfs # Made Red Hat files configurable. # # Revision 1.28 2003/07/23 18:13:52 dfs # Added MD_EXTRA setting. # # Revision 1.27 2003/07/01 21:33:50 dfs # Init scripts set locale to "C" # # Revision 1.26 2003/06/20 18:03:14 dfs # Added queue stuff to init scripts. # # Revision 1.25 2003/06/04 14:14:59 dfs # Fixed typo # # Revision 1.24 2003/06/04 14:03:33 dfs # Copy pid files into /var/run to keep Red Hat killproc() happy. # # Revision 1.23 2003/05/27 14:50:21 dfs # Default quarantine dir is /var/spool/MD-Quarantine # Removed support for non-multiplexor operation. # # Revision 1.22 2003/04/21 16:27:46 dfs # Added SYSLOG_FACILITY to init scripts. # Fixed typo. # # Revision 1.21 2003/03/05 15:30:28 dfs # Added -L option # # Revision 1.20 2002/12/03 17:44:47 dfs # Do "ulimit -s" if lots of slaves. # # Revision 1.19 2002/09/18 15:47:49 dfs # Updated init scripts for "-T" option. # # Revision 1.18 2002/06/13 14:58:28 dfs # Updated changelog. # # Revision 1.17 2002/06/11 13:36:10 dfs # Update scripts for recipient checks. # # Revision 1.16 2002/05/29 18:12:15 dfs # Put pid files and sockets in /var/spool/MIMEDefang instead of /var/run # # Revision 1.15 2002/05/17 12:49:42 dfs # Fixed typo. # # Revision 1.14 2002/05/17 12:48:34 dfs # Added reload as a synonym for reread. # # Revision 1.13 2002/05/15 13:39:02 dfs # Added README.NONROOT # # Revision 1.12 2002/05/15 13:08:43 dfs # Made init script use -U for mimedefang too. # # Revision 1.11 2002/05/15 12:55:02 dfs # Infrastructure for running multiplexor as non-root. # # Revision 1.10 2002/05/10 12:36:53 dfs # Changed MX_SLAVE_RATE to MX_SLAVE_DELAY; added MX_MIN_SLAVE_DELAY. # # Revision 1.9 2002/05/08 16:55:17 dfs # Updated redhat init scripts for subfilter. # # Revision 1.8 2002/05/06 18:36:08 dfs # Added MX_SLAVE_RATE to init scripts. # # Revision 1.7 2002/05/03 14:58:55 dfs # Fixed init script to look in /usr/bin and /usr/local/bin # # Revision 1.6 2002/05/03 14:24:24 dfs # Merge packaging patches. # Fixed typo. # Made default value for -n 10. # ########################################################################## # These comments are used by chkconfig and supporting programs # # chkconfig: 2345 79 31 # description: mimedefang is a sendmail milter designed to perform virus \ # scans on incoming mail messages. # processname: mimedefang # config: @CONFDIR_EVAL@/mimedefang-filter # pidfile: @SPOOLDIR@/mimedefang.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network RETVAL=0 prog="mimedefang" # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 # Is the program executable? We search in /usr/bin and /usr/local/bin # so that both RPM and normal installation methods work fine. if [ -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 fi # Make sure reqired vars are set SOCKET=${SOCKET:=@SPOOLDIR@/$prog.sock} MX_SOCKET=${MX_SOCKET:=@SPOOLDIR@/$prog-multiplexor.sock} # Locale should be set to "C" for generating valid date headers LC_ALL=C export LC_ALL start() { # Lets not run twice if [ -f /var/lock/subsys/$prog ]; then RETVAL=2 return $RETVAL fi echo -n "Starting $prog-multiplexor: " [ -e $MX_SOCKET ] && rm -f $MX_SOCKET # Tricky stuff below... "echo -E" won't work, hence the two-step. daemon $PROGDIR/$prog-multiplexor -p @SPOOLDIR@/$prog-multiplexor.pid \ $([ -n "$FILTER" ] && echo "-f $FILTER") \ $([ -n "$SYSLOG_FACILITY" ] && echo "-S $SYSLOG_FACILITY") \ $([ -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_QUEUE_SIZE" ] && echo "-q $MX_QUEUE_SIZE") \ $([ -n "$MX_QUEUE_TIMEOUT" ] && echo "-Q $MX_QUEUE_TIMEOUT") \ $([ -n "$MX_REQUESTS" ] && echo "-r $MX_REQUESTS") \ $([ -n "$MX_MAP_SOCKET" ] && echo "-N $MX_MAP_SOCKET") \ $([ -n "$MX_SLAVE_DELAY" ] && echo "-w $MX_SLAVE_DELAY") \ $([ -n "$MX_MIN_SLAVE_DELAY" ] && echo "-W $MX_MIN_SLAVE_DELAY") \ $([ -n "$MX_LOG_SLAVE_STATUS_INTERVAL" ] && echo "-L $MX_LOG_SLAVE_STATUS_INTERVAL") \ $([ -n "$MX_MAX_RSS" ] && echo "-R $MX_MAX_RSS") \ $([ -n "$MX_MAX_AS" ] && echo "-M $MX_MAX_AS") \ $([ "$MX_EMBED_PERL" = "yes" ] && (echo -n "-"; echo "E")) \ $([ "$MX_LOG" = "yes" ] && echo "-l") \ $([ "$MX_STATS" = "yes" ] && echo "-t /var/log/mimedefang/stats") \ $([ "$MX_STATUS_UPDATES" = "yes" ] && echo "-Z") \ $([ "$MX_STATS" = "yes" -a "$MX_FLUSH_STATS" = "yes" ] && echo "-u") \ $([ "$MX_STATS_SYSLOG" = "yes" ] && echo "-T") \ $([ -n "$MX_NOTIFIER" ] && echo "-O $MX_NOTIFIER") \ -s $MX_SOCKET echo # Start daemon echo -n "Starting $prog: " [ -e $SOCKET ] && rm -f $SOCKET # NOTE: You should limit the stack size on Linux, or # thread-creation will fail on a very busy server. ulimit -s 2048 daemon $PROGDIR/$prog -P @SPOOLDIR@/$prog.pid \ -m $MX_SOCKET \ $([ -n "$MX_USER" ] && echo "-U $MX_USER") \ $([ -n "$SYSLOG_FACILITY" ] && echo "-S $SYSLOG_FACILITY") \ $([ "$LOG_FILTER_TIME" = "yes" ] && echo "-T") \ $([ "$MX_RELAY_CHECK" = "yes" ] && echo "-r") \ $([ "$MX_SENDER_CHECK" = "yes" ] && echo "-s") \ $([ "$MX_RECIPIENT_CHECK" = "yes" ] && echo "-t") \ $([ "$KEEP_FAILED_DIRECTORIES" = "yes" ] && echo "-k") \ $([ -n "$MD_EXTRA" ] && echo "$MD_EXTRA") \ -p $SOCKET RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog # Red Hat gets upset if pid files are not under /var/run, so let's # keep Red Hat happy... sleep 1 [ -f @SPOOLDIR@/$prog.pid ] && cp -f @SPOOLDIR@/$prog.pid /var/run [ -f @SPOOLDIR@/$prog-multiplexor.pid ] && cp -f @SPOOLDIR@/$prog-multiplexor.pid /var/run return $RETVAL } stop() { # If we're not running, there's nothing to do if [ ! -f /var/lock/subsys/$prog ]; then RETVAL=2 return $RETVAL fi # Stop daemon echo -n "Shutting down $prog: " killproc $prog RETVAL=$? echo [ -e $SOCKET ] && rm -f $SOCKET [ -f @SPOOLDIR@/$prog.pid ] && rm -f @SPOOLDIR@/$prog.pid [ -f /var/run/$prog.pid ] && rm -f /var/run/$prog.pid # Stop daemon echo -n "Shutting down $prog-multiplexor: " killproc $prog-multiplexor echo [ -e $MX_SOCKET ] && rm -f $MX_SOCKET if [ "$1" = "wait" ] ; then printf "Waiting for daemons to exit" WAITPID="" test -f @SPOOLDIR@/$prog.pid && WAITPID=`cat @SPOOLDIR@/$prog.pid` test -f @SPOOLDIR@/prog-multiplexor.pid && WAITPID="$WAITPID `cat @SPOOLDIR@/prog-multiplexor.pid`" n=0 while [ -n "$WAITPID" ] ; do W2="" for pid in $WAITPID ; do if kill -0 $pid > /dev/null 2>&1 ; then W2="$W2 $pid" fi done printf "." n=`expr $n + 1` test $n -eq 30 && kill -KILL $WAITPID > /dev/null 2>&1 test $n -eq 60 && break WAITPID=$W2 sleep 1 done echo "" fi [ -f @SPOOLDIR@/$prog-multiplexor.pid ] && rm -f @SPOOLDIR@/$prog-multiplexor.pid [ -f /var/run/$prog-multiplexor.pid ] && rm -f /var/run/$prog-multiplexor.pid [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog return $RETVAL } # See how we were called. case "$1" in start) start ;; stop) stop $2 ;; restart) stop wait start RETVAL=$? ;; condrestart) if [ -f /var/lock/subsys/$prog ]; then stop wait start RETVAL=$? fi ;; status) status $prog status $prog-multiplexor RETVAL=$? if [ $RETVAL = 0 -a -x $PROGDIR/md-mx-ctrl ] ; then $PROGDIR/md-mx-ctrl -s $MX_SOCKET barstatus fi ;; reread|reload) if [ -x $PROGDIR/md-mx-ctrl ] ; then $PROGDIR/md-mx-ctrl -s $MX_SOCKET reread > /dev/null 2>&1 RETVAL=$? if [ $RETVAL = 0 ] ; then echo "Told $prog-multiplexor to force reread of filter rules." else echo "Could not communicate with $prog-multiplexor" fi else if [ -r @SPOOLDIR@/$prog-multiplexor.pid ] ; then kill -INT `cat @SPOOLDIR@/$prog-multiplexor.pid` 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 fi ;; *) echo "Usage: $0 {start|stop|restart|condrestart|reread|reload|status}" exit 1 esac exit $RETVAL