File rc.amavis of Package amavisd-new

#! /bin/sh
# Copyright (c) 2008 SuSE Linux AG Nuernberg, Germany.
#
# Author: Carsten Hoeger <feedback@suse.de>, 2003
#
# /etc/init.d/amavis
#   and its symbolic link
# /usr/sbin/rcamavis
#
### BEGIN INIT INFO
# Provides:          amavis
# Required-Start:    $remote_fs
# Should-Start:      $named clamd
# Should-Stop:	     $named clamd
# Required-Stop:     $remote_fs
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Start amavisd-new
# Description:       Amavisd-new is a high-performance interface between mailer (MTA) and
#	content checkers: virus scanners or SpamAssassin. It talks to the MTA
#	via (E)SMTP, LMTP, or by using helper programs.
### END INIT INFO

AMAVISD_BIN=/usr/sbin/amavisd
AMAVIS_MILTER_BIN=/usr/sbin/amavisd-milter
AMAVIS_SYSCONFIG=/etc/sysconfig/amavis
AMAVIS_CONF=/etc/amavisd.conf
AMAVIS_PID=/var/spool/amavis/amavisd.pid
AMAVIS_MILTER_PID=/var/spool/amavis/amavisd-milter.pid
AMAVIS_MILTER_SOCK=local:/var/spool/amavis/amavis-milter.sock
# Use local TCP socket
# AMAVIS_MILTER_SOCK=inet:10024@localhost

# it's like checkproc, but works for scripts too:
checkproc_script()
{
    if [ "${1}" = "-p" ]; then
	if [ -z "${2}" -o -z "${3}" ]; then
	    return 101
	fi
	CHECK_PID=`cat "${2}"`;
	if [ -e /proc/"${CHECK_PID}" ]; then
	    CHECK_EXE="${3}";
	    FOUND=`cat /proc/"${CHECK_PID}"/cmdline | grep "${CHECK_EXE}"`
	    if [ -n "${FOUND}" ]; then
		return 0;
	    else
		return 1;
	    fi
	else
	    return 3;
	fi
    elif [ -z "${2}" ]; then
	CHECK_EXE="${1}";
	FOUND=`ps auxwww | grep "${CHECK_EXE}"`
	if [ -n "${FOUND}" ]; then
	    return 0;
	else
    	    return 7;
	fi
    fi

    return 101;
}

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
test -x $AMAVISD_BIN || { echo "$AMAVIS_BIN not installed";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

test -x $AMAVIS_MILTER_BIN || { echo "$AMAVIS_MILTER_BIN not installed";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 5; fi; }

# Check for existence of needed config file and read it
test -r $AMAVIS_SYSCONFIG || { echo "$AMAVIS_SYSCONFIG not existing";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 6; fi; }

test -r $AMAVIS_CONF || { echo "$AMAVIS_CONF not existing";
    if [ "$1" = "stop" ]; then exit 0;
    else exit 6; fi; }

# Read config
. $AMAVIS_SYSCONFIG

# Shell functions sourced from /etc/rc.status
. /etc/rc.status

# First reset status of this service
rc_reset

case "$1" in
    start)
	# ZMI 20100428 check for stale pid file
	if test -f $AMAVIS_PID ; then
		checkproc_script -p $AMAVIS_PID $AMAVISD_BIN
		if test $? -ge 1 ; then
			# pid file is stale, remove it
			echo -n "(stale amavisd pid file $AMAVIS_PID found, removing. Did amavisd crash?)"
			rm -f $AMAVIS_PID
		fi
	fi
        echo -n "Starting virus-scanner (amavisd-new): "
        $AMAVISD_BIN start
	if ! checkproc_script $AMAVISD_BIN; then
            rc_failed 7
        fi
        rc_status -v
        if [ "$AMAVIS_SENDMAIL_MILTER" == "yes" ]; then
            rc_reset
            echo -n "Starting amavisd-milter:"
            startproc -u vscan $AMAVIS_MILTER_BIN -s $AMAVIS_MILTER_SOCK \
	      -p $AMAVIS_MILTER_PID > /dev/null 2>&1
            rc_status -v
        fi
	;;
    stop)
        echo -n "Shutting down virus-scanner (amavisd-new): "
        if checkproc_script $AMAVISD_BIN; then
            rc_reset
            $AMAVISD_BIN stop
        else
            rc_reset
        fi
        rc_status -v
        if [ "$AMAVIS_SENDMAIL_MILTER" == "yes" ]; then
            rc_reset
            echo -n "Shutting down amavis-milter: "
            killproc -TERM $AMAVIS_MILTER_BIN
            rc_status -v
        fi
	;;
    try-restart)
        $0 status >/dev/null &&  $0 restart
        rc_status
    ;;
    restart)
        $0 stop
        $0 start
        rc_status
	;;
    force-reload)
        echo -n "Reload virus-scanner (amavisd-new): "
        $AMAVISD_BIN reload 2>/dev/null
        rc_status -v
    ;;
    reload)
        echo -n "Reload virus-scanner (amavisd-new): "
        $AMAVISD_BIN reload 2>/dev/null
        rc_status -v
    ;;
    status)
        echo -n "Checking for service amavis (amavisd-new): "
        checkproc_script -p $AMAVIS_PID $AMAVISD_BIN
        rc_status -v
        if [ "$AMAVIS_SENDMAIL_MILTER" == "yes" ]; then
            rc_reset
            echo -n "Checking for service amavis-milter: "
            checkproc_script $AMAVIS_MILTER_BIN
            rc_status -v
        fi
    ;;
    probe)
        ## Optional: Probe for the necessity of a reload, print out the
        ## argument to this init script which is required for a reload.
        test $AMAVIS_CONF -nt /var/spool/amavis/amavisd.pid && echo reload
    ;;
    *)
        echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}"
        exit 1
    ;;
esac
# Inform the caller not only verbosely and set an exit status.
rc_exit
openSUSE Build Service is sponsored by