xref: /onnv-gate/usr/src/cmd/sendmail/lib/smtp-sendmail (revision 2104:ce72b74b05fd)
10Sstevel@tonic-gate#!/sbin/sh
20Sstevel@tonic-gate#
30Sstevel@tonic-gate# CDDL HEADER START
40Sstevel@tonic-gate#
50Sstevel@tonic-gate# The contents of this file are subject to the terms of the
6*2104Sjjj# Common Development and Distribution License (the "License").
7*2104Sjjj# You may not use this file except in compliance with the License.
80Sstevel@tonic-gate#
90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate# See the License for the specific language governing permissions
120Sstevel@tonic-gate# and limitations under the License.
130Sstevel@tonic-gate#
140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate#
200Sstevel@tonic-gate# CDDL HEADER END
210Sstevel@tonic-gate#
22*2104Sjjj# Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate# Use is subject to license terms.
240Sstevel@tonic-gate#
250Sstevel@tonic-gate# ident	"%Z%%M%	%I%	%E% SMI"
260Sstevel@tonic-gate
270Sstevel@tonic-gate. /lib/svc/share/smf_include.sh
280Sstevel@tonic-gate
290Sstevel@tonic-gateERRMSG1='WARNING: /var/mail is NFS-mounted without setting actimeo=0,'
300Sstevel@tonic-gateERRMSG2='this can cause mailbox locking and access problems.'
310Sstevel@tonic-gateSERVER_PID_FILE="/var/run/sendmail.pid"
320Sstevel@tonic-gateCLIENT_PID_FILE="/var/spool/clientmqueue/sm-client.pid"
330Sstevel@tonic-gateDEFAULT_FILE="/etc/default/sendmail"
340Sstevel@tonic-gateALIASES_FILE="/etc/mail/aliases"
350Sstevel@tonic-gate
360Sstevel@tonic-gatecheck_queue_interval_syntax()
370Sstevel@tonic-gate{
380Sstevel@tonic-gate	default="15m"
390Sstevel@tonic-gate	if [ $# -lt 1 ]; then
400Sstevel@tonic-gate		answer=$default
410Sstevel@tonic-gate		return
420Sstevel@tonic-gate	fi
430Sstevel@tonic-gate	if echo $1 | egrep '^([0-9]*[1-9][0-9]*[smhdw])+$' >/dev/null 2>&1; then
440Sstevel@tonic-gate		answer=$1
450Sstevel@tonic-gate	else
460Sstevel@tonic-gate		answer=$default
470Sstevel@tonic-gate	fi
480Sstevel@tonic-gate}
490Sstevel@tonic-gate
500Sstevel@tonic-gatecheck_and_kill()
510Sstevel@tonic-gate{
520Sstevel@tonic-gate	PID=`head -1 $1`
530Sstevel@tonic-gate	kill -0 $PID > /dev/null 2>&1
540Sstevel@tonic-gate	[ $? -eq 0 ] && kill $PID
550Sstevel@tonic-gate}
560Sstevel@tonic-gate
570Sstevel@tonic-gatecase "$1" in
580Sstevel@tonic-gate'refresh')
590Sstevel@tonic-gate        [ -f $SERVER_PID_FILE ] && kill -1 `head -1 $SERVER_PID_FILE`
600Sstevel@tonic-gate        [ -f $CLIENT_PID_FILE ] && kill -1 `head -1 $CLIENT_PID_FILE`
610Sstevel@tonic-gate        ;;
620Sstevel@tonic-gate
630Sstevel@tonic-gate'start')
640Sstevel@tonic-gate	if [ ! -f /usr/lib/sendmail -o ! -f /etc/mail/sendmail.cf ]; then
650Sstevel@tonic-gate		exit $SMF_EXIT_ERR_CONFIG
660Sstevel@tonic-gate	fi
670Sstevel@tonic-gate	if [ ! -d /var/spool/mqueue ]; then
680Sstevel@tonic-gate		/usr/bin/mkdir -m 0750 /var/spool/mqueue
690Sstevel@tonic-gate		/usr/bin/chown root:bin /var/spool/mqueue
700Sstevel@tonic-gate	fi
710Sstevel@tonic-gate	if [ ! -f $ALIASES_FILE.db ] && [ ! -f $ALIASES_FILE.dir ] \
720Sstevel@tonic-gate	    && [ ! -f $ALIASES_FILE.pag ]; then
730Sstevel@tonic-gate		/usr/sbin/newaliases
740Sstevel@tonic-gate	fi
750Sstevel@tonic-gate	MODE="-bd"
760Sstevel@tonic-gate	[ -f $DEFAULT_FILE ] && . $DEFAULT_FILE
770Sstevel@tonic-gate	#
780Sstevel@tonic-gate	# * MODE should be "-bd" or null (MODE= or MODE="") or
790Sstevel@tonic-gate	#   left alone.  Anything else and you're on your own.
800Sstevel@tonic-gate	# * QUEUEOPTION should be "p" or null (as above).
810Sstevel@tonic-gate	# * [CLIENT]QUEUEINTERVAL should be set to some legal value;
820Sstevel@tonic-gate	#   sanity checks are done below.
830Sstevel@tonic-gate	# * [CLIENT]OPTIONS are catch-alls; set with care.
840Sstevel@tonic-gate	#
850Sstevel@tonic-gate	if [ -n "$QUEUEOPTION" -a "$QUEUEOPTION" != "p" ]; then
860Sstevel@tonic-gate		QUEUEOPTION=""
870Sstevel@tonic-gate	fi
880Sstevel@tonic-gate	if [ -z "$QUEUEOPTION" -o -n "$QUEUEINTERVAL" ]; then
890Sstevel@tonic-gate		check_queue_interval_syntax $QUEUEINTERVAL
900Sstevel@tonic-gate		QUEUEINTERVAL=$answer
910Sstevel@tonic-gate	fi
920Sstevel@tonic-gate	check_queue_interval_syntax $CLIENTQUEUEINTERVAL
930Sstevel@tonic-gate	CLIENTQUEUEINTERVAL=$answer
94*2104Sjjj
95*2104Sjjj	local=`/usr/bin/svcprop -p config/local_only $SMF_FMRI 2>/dev/null`
96*2104Sjjj	if [ $? = 0 -a "$local" = "true" ]; then
97*2104Sjjj		OPTIONS="$OPTIONS -C /etc/mail/local.cf"
98*2104Sjjj	fi
99*2104Sjjj
1000Sstevel@tonic-gate	/usr/lib/sendmail $MODE -q$QUEUEOPTION$QUEUEINTERVAL $OPTIONS &
1010Sstevel@tonic-gate	/usr/lib/sendmail -Ac -q$CLIENTQUEUEINTERVAL $CLIENTOPTIONS &
102*2104Sjjj
1030Sstevel@tonic-gate	#
1040Sstevel@tonic-gate	# ETRN_HOSTS should be of the form
1050Sstevel@tonic-gate	# "s1:c1.1,c1.2        s2:c2.1 s3:c3.1,c3.2,c3.3"
1060Sstevel@tonic-gate	# i.e., white-space separated groups of server:client where
1070Sstevel@tonic-gate	# client can be one or more comma-separated names; N.B. that
1080Sstevel@tonic-gate	# the :client part is optional; see etrn(1M) for details.
1090Sstevel@tonic-gate	# server is the name of the server to prod; a mail queue run
1100Sstevel@tonic-gate	# is requested for each client name.  This is comparable to
1110Sstevel@tonic-gate	# running "/usr/lib/sendmail -qRclient" on the host server.
1120Sstevel@tonic-gate	#
1130Sstevel@tonic-gate	# See RFC 1985 for more information.
1140Sstevel@tonic-gate	#
1150Sstevel@tonic-gate	for i in $ETRN_HOSTS; do
1160Sstevel@tonic-gate		SERVER=`echo $i | /usr/bin/sed -e 's/:.*$//'`
1170Sstevel@tonic-gate		CLIENTS=`echo $i | /usr/bin/sed -n -e 's/,/ /g' \
1180Sstevel@tonic-gate		    -e '/:/s/^.*://p'`
1190Sstevel@tonic-gate		/usr/sbin/etrn -b $SERVER $CLIENTS >/dev/null 2>&1 &
1200Sstevel@tonic-gate	done
1210Sstevel@tonic-gate
1220Sstevel@tonic-gate	if /usr/bin/nawk 'BEGIN{s = 1}
1230Sstevel@tonic-gate	    $2 == "/var/mail" && $3 == "nfs" && $4 !~ /actimeo=0/ &&
1240Sstevel@tonic-gate	    $4 !~ /noac/{s = 0} END{exit s}' /etc/mnttab; then
1250Sstevel@tonic-gate
1260Sstevel@tonic-gate		/usr/bin/logger -p mail.crit "$ERRMSG1"
1270Sstevel@tonic-gate		/usr/bin/logger -p mail.crit "$ERRMSG2"
1280Sstevel@tonic-gate	fi
1290Sstevel@tonic-gate	;;
1300Sstevel@tonic-gate
1310Sstevel@tonic-gate'stop')
1320Sstevel@tonic-gate	[ -f $SERVER_PID_FILE ] && check_and_kill $SERVER_PID_FILE
1330Sstevel@tonic-gate	if [ -f $CLIENT_PID_FILE ]; then
1340Sstevel@tonic-gate		check_and_kill $CLIENT_PID_FILE
1350Sstevel@tonic-gate		rm -f $CLIENT_PID_FILE
1360Sstevel@tonic-gate	fi
1370Sstevel@tonic-gate	# Need to kill the entire service contract to kill all sendmail related
1380Sstevel@tonic-gate	# processes
1390Sstevel@tonic-gate	smf_kill_contract $2 TERM 1 30
1400Sstevel@tonic-gate	ret=$?
1410Sstevel@tonic-gate	[ $ret -eq 1 ] && exit 1
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate	# Since sendmail spawns user processes out of .forward files, it is
1440Sstevel@tonic-gate	# possible that some of these are not responding to TERM.  If the
1450Sstevel@tonic-gate	# contract did not empty after TERM, move on to KILL.
1460Sstevel@tonic-gate	if [ $ret -eq 2 ] ; then
1470Sstevel@tonic-gate		smf_kill_contract $2 KILL 1
1480Sstevel@tonic-gate	fi
1490Sstevel@tonic-gate	;;
1500Sstevel@tonic-gate
1510Sstevel@tonic-gate*)
1520Sstevel@tonic-gate	echo "Usage: $0 { start | stop | refresh }"
1530Sstevel@tonic-gate	exit 1
1540Sstevel@tonic-gate	;;
1550Sstevel@tonic-gateesac
1560Sstevel@tonic-gateexit 0
157