lkundrak / rpms / sendmail

Forked from rpms/sendmail 4 years ago
Clone
cvsdist 83f6af4
#!/bin/bash
cvsdist 53226c2
#
cvsdist 53226c2
# sendmail      This shell script takes care of starting and stopping
cvsdist 53226c2
#               sendmail.
cvsdist 53226c2
#
cvsdist 53226c2
# chkconfig: 2345 80 30
cvsdist 53226c2
# description: Sendmail is a Mail Transport Agent, which is the program \
cvsdist 53226c2
#              that moves mail from one machine to another.
cvsdist 53226c2
# processname: sendmail
cvsdist 333a3fa
# config: /etc/mail/sendmail.cf
cvsdist 53226c2
# pidfile: /var/run/sendmail.pid
cvsdist 53226c2
91a157a
### BEGIN INIT INFO
91a157a
# Provides: sendmail MTA smtpdaemon
91a157a
# Required-Start: $local_fs $network
91a157a
# Required-Stop: $local_fs $network
91a157a
# Default-Start: 2 3 4 5
91a157a
# Default-Stop: 0 1 6
91a157a
# Short-Description: start and stop sendmail
91a157a
# Description: sendmail is a Mail Transport Agent (MTA)
91a157a
### END INIT INFO
91a157a
cvsdist 53226c2
# Source function library.
cvsdist 849c77a
. /etc/rc.d/init.d/functions
cvsdist 53226c2
cvsdist 53226c2
# Source networking configuration.
cvsdist 35607f7
[ -f /etc/sysconfig/network ] && . /etc/sysconfig/network
cvsdist 53226c2
cvsdist 53226c2
# Source sendmail configureation.
91a157a
if [ -f /etc/sysconfig/sendmail ]; then
91a157a
    . /etc/sysconfig/sendmail
cvsdist 53226c2
else
91a157a
    DAEMON=no
91a157a
    QUEUE=1h
cvsdist 53226c2
fi
cvsdist 68b31f4
[ -z "$SMQUEUE" ] && SMQUEUE="$QUEUE"
cvsdist 68b31f4
[ -z "$SMQUEUE" ] && SMQUEUE=1h
cvsdist 53226c2
cvsdist 53226c2
# Check that networking is up.
91a157a
[ "${NETWORKING}" = "no" ] && exit 1
cvsdist 53226c2
91a157a
[ -f /usr/sbin/sendmail ] || exit 5
cvsdist 53226c2
cvsdist 83f6af4
prog="sendmail"
cvsdist 53226c2
cvsdist 53226c2
start() {
91a157a
    # Start daemons.
91a157a
    ret=0
91a157a
    echo -n $"Starting $prog: "
91a157a
    if [ -x /usr/bin/make -a -f /etc/mail/Makefile ]; then
91a157a
	make all -C /etc/mail -s > /dev/null
91a157a
    else
91a157a
	for i in virtusertable access domaintable mailertable ; do
91a157a
	    [ -f /etc/mail/$i ] && makemap hash /etc/mail/$i < /etc/mail/$i
91a157a
	    let ret+=$?
91a157a
	done
91a157a
    fi
91a157a
    /usr/bin/newaliases > /dev/null 2>&1
91a157a
    daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) \
91a157a
	$([ -n "$QUEUE" ] && echo -q$QUEUE) $SENDMAIL_OPTARG
91a157a
    RETVAL=$?
91a157a
    echo
91a157a
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/sendmail
91a157a
    let ret+=$RETVAL
cvsdist 333a3fa
91a157a
    if [ ! -f /var/run/sm-client.pid ]; then
cvsdist 333a3fa
	echo -n $"Starting sm-client: "
cvsdist 333a3fa
	touch /var/run/sm-client.pid
cvsdist 333a3fa
	chown smmsp:smmsp /var/run/sm-client.pid
36b7a28
	if [ -x /usr/sbin/selinuxenabled ] && /usr/sbin/selinuxenabled; then
cvsdist a9c0552
	    /sbin/restorecon /var/run/sm-client.pid
cvsdist a9c0552
	fi
cvsdist 333a3fa
	daemon --check sm-client /usr/sbin/sendmail -L sm-msp-queue -Ac \
91a157a
	    -q$SMQUEUE $SENDMAIL_OPTARG
cvsdist 333a3fa
	RETVAL=$?
91a157a
	echo
91a157a
	[ $RETVAL -eq 0 ] && touch /var/lock/subsys/sm-client
91a157a
	let ret+=$RETVAL
91a157a
    fi
cvsdist 333a3fa
91a157a
    [ $ret -eq 0 ] && return 0 || return 1
cvsdist 53226c2
}
cvsdist 53226c2
cvsdist 2ddbe24
reload() {
91a157a
    # Stop daemons.
91a157a
    ret=0
91a157a
    echo -n $"Reloading $prog: "
91a157a
    /usr/bin/newaliases > /dev/null 2>&1
91a157a
    if [ -x /usr/bin/make -a -f /etc/mail/Makefile ]; then
91a157a
	make all -C /etc/mail -s > /dev/null
91a157a
    else
91a157a
	for i in virtusertable access domaintable mailertable ; do
91a157a
	    [ -f /etc/mail/$i ] && makemap hash /etc/mail/$i < /etc/mail/$i
91a157a
	done
91a157a
    fi
91a157a
    daemon /usr/sbin/sendmail $([ "x$DAEMON" = xyes ] && echo -bd) \
91a157a
	$([ -n "$QUEUE" ] && echo -q$QUEUE)
91a157a
    RETVAL=$?
91a157a
    killproc sendmail -HUP
91a157a
    RETVAL=$?
91a157a
    echo
91a157a
    if [ $RETVAL -eq 0 -a -f /var/run/sm-client.pid ]; then
91a157a
        echo -n $"reloading sm-client: "
91a157a
	killproc sm-client -HUP
cvsdist 2ddbe24
	RETVAL=$?
cvsdist 2ddbe24
	echo
91a157a
    fi
91a157a
    return $RETVAL
cvsdist 2ddbe24
}
cvsdist 2ddbe24
cvsdist 53226c2
stop() {
91a157a
    # Stop daemons.
91a157a
    if [ -f /var/run/sm-client.pid ]; then
91a157a
	echo -n $"Shutting down sm-client: "
91a157a
	killproc sm-client
a849b7d
	RETVAL=$?
a849b7d
	echo
91a157a
	[ $RETVAL -eq 0 ] && rm -f /var/run/sm-client.pid
91a157a
	[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sm-client
91a157a
    fi
91a157a
    echo -n $"Shutting down $prog: "
91a157a
    killproc sendmail
91a157a
    RETVAL=$?
91a157a
    echo
91a157a
    [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/sendmail
91a157a
    return $RETVAL
cvsdist 53226c2
}
cvsdist 53226c2
91a157a
status -p /var/run/sendmail.pid >/dev/null && status -p /var/run/sm-client.pid >/dev/null
91a157a
running=$?
91a157a
cvsdist 53226c2
# See how we were called.
cvsdist 53226c2
case "$1" in
91a157a
    start)
91a157a
	[ $running -eq 0 ] && exit 0
cvsdist 53226c2
	start
91a157a
	RETVAL=$?
cvsdist 53226c2
	;;
91a157a
    stop)
91a157a
	[ $running -ne 0 ] || exit 0
cvsdist 53226c2
	stop
91a157a
	RETVAL=$?
cvsdist 53226c2
	;;
91a157a
    reload)
91a157a
	[ $running -ne 0 ] && exit 7
cvsdist 2ddbe24
	reload
cvsdist 2ddbe24
	RETVAL=$?
cvsdist 2ddbe24
	;;
91a157a
    restart|force-reload)
cvsdist 53226c2
	stop
cvsdist 53226c2
	start
cvsdist 53226c2
	RETVAL=$?
cvsdist 53226c2
	;;
91a157a
    condrestart|try-restart)
91a157a
	[ ! -f /var/lock/subsys/sendmail ] && exit 7
91a157a
	stop
91a157a
	start
91a157a
	RETVAL=$?
cvsdist 53226c2
	;;
91a157a
    status)
91a157a
	echo -n sendmail; status -p /var/run/sendmail.pid
cvsdist 53226c2
	RETVAL=$?
91a157a
	echo -n sm-client; status -p /var/run/sm-client.pid
91a157a
	[ $RETVAL -eq 0 ] && RETVAL=$?
cvsdist 53226c2
	;;
91a157a
    *)
cvsdist 83f6af4
	echo $"Usage: $0 {start|stop|restart|condrestart|status}"
91a157a
	RETVAL=3
cvsdist 53226c2
esac
cvsdist 53226c2
cvsdist 53226c2
exit $RETVAL