17c478bd9Sstevel@tonic-gate#!/sbin/sh
27c478bd9Sstevel@tonic-gate#
37c478bd9Sstevel@tonic-gate# CDDL HEADER START
47c478bd9Sstevel@tonic-gate#
57c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the
60ea5e3a5Sjjj# Common Development and Distribution License (the "License").
70ea5e3a5Sjjj# You may not use this file except in compliance with the License.
87c478bd9Sstevel@tonic-gate#
97c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate# and limitations under the License.
137c478bd9Sstevel@tonic-gate#
147c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate#
207c478bd9Sstevel@tonic-gate# CDDL HEADER END
217c478bd9Sstevel@tonic-gate#
22da978630SJohn Beck# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate# Use is subject to license terms.
247c478bd9Sstevel@tonic-gate
257c478bd9Sstevel@tonic-gate. /lib/svc/share/smf_include.sh
26da978630SJohn Beck. /lib/svc/share/sendmail_include.sh
277c478bd9Sstevel@tonic-gate
287c478bd9Sstevel@tonic-gateERRMSG1='WARNING: /var/mail is NFS-mounted without setting actimeo=0,'
297c478bd9Sstevel@tonic-gateERRMSG2='this can cause mailbox locking and access problems.'
307c478bd9Sstevel@tonic-gateSERVER_PID_FILE="/var/run/sendmail.pid"
317c478bd9Sstevel@tonic-gateALIASES_FILE="/etc/mail/aliases"
32d4660949SjbeckSENDMAIL_CF="/etc/mail/sendmail.cf"
33d4660949Sjbeck
34*2844a237SAndy Fiddamancase "$1" in
357c478bd9Sstevel@tonic-gate'refresh')
367c478bd9Sstevel@tonic-gate        [ -f $SERVER_PID_FILE ] && kill -1 `head -1 $SERVER_PID_FILE`
377c478bd9Sstevel@tonic-gate        ;;
387c478bd9Sstevel@tonic-gate
397c478bd9Sstevel@tonic-gate'start')
40d4660949Sjbeck	exist_or_exit $SENDMAIL
417c478bd9Sstevel@tonic-gate	if [ ! -d /var/spool/mqueue ]; then
427c478bd9Sstevel@tonic-gate		/usr/bin/mkdir -m 0750 /var/spool/mqueue
437c478bd9Sstevel@tonic-gate		/usr/bin/chown root:bin /var/spool/mqueue
447c478bd9Sstevel@tonic-gate	fi
457c478bd9Sstevel@tonic-gate	if [ ! -f $ALIASES_FILE.db ] && [ ! -f $ALIASES_FILE.dir ] \
467c478bd9Sstevel@tonic-gate	    && [ ! -f $ALIASES_FILE.pag ]; then
47*2844a237SAndy Fiddaman		# Create the aliases database
48*2844a237SAndy Fiddaman		$SENDMAIL -bi
497c478bd9Sstevel@tonic-gate	fi
507c478bd9Sstevel@tonic-gate	MODE="-bd"
517c478bd9Sstevel@tonic-gate	[ -f $DEFAULT_FILE ] && . $DEFAULT_FILE
527c478bd9Sstevel@tonic-gate	#
537c478bd9Sstevel@tonic-gate	# * MODE should be "-bd" or null (MODE= or MODE="") or
547c478bd9Sstevel@tonic-gate	#   left alone.  Anything else and you're on your own.
557c478bd9Sstevel@tonic-gate	# * QUEUEOPTION should be "p" or null (as above).
56da978630SJohn Beck	# * QUEUEINTERVAL should be set to some legal value;
577c478bd9Sstevel@tonic-gate	#   sanity checks are done below.
58da978630SJohn Beck	# * OPTIONS are catch-alls; set with care.
597c478bd9Sstevel@tonic-gate	#
607c478bd9Sstevel@tonic-gate	if [ -n "$QUEUEOPTION" -a "$QUEUEOPTION" != "p" ]; then
617c478bd9Sstevel@tonic-gate		QUEUEOPTION=""
627c478bd9Sstevel@tonic-gate	fi
637c478bd9Sstevel@tonic-gate	if [ -z "$QUEUEOPTION" -o -n "$QUEUEINTERVAL" ]; then
647c478bd9Sstevel@tonic-gate		check_queue_interval_syntax $QUEUEINTERVAL
657c478bd9Sstevel@tonic-gate		QUEUEINTERVAL=$answer
667c478bd9Sstevel@tonic-gate	fi
670ea5e3a5Sjjj
680ea5e3a5Sjjj	local=`/usr/bin/svcprop -p config/local_only $SMF_FMRI 2>/dev/null`
69d4660949Sjbeck	if [ $? -eq 0 -a "$local" = "true" ]; then
70d4660949Sjbeck		MODE="-bl"
71d4660949Sjbeck	fi
72d4660949Sjbeck	sendmail_path=`svcprop -p config/path_to_sendmail_mc $SMF_FMRI \
73d4660949Sjbeck	    2>/dev/null`
74d4660949Sjbeck	if [ $? -eq 0 -a -n "$sendmail_path" ]; then
7539b0b3b7SJohn Beck		turn_m4_crank "$SENDMAIL_CF" "$sendmail_path"
76d4660949Sjbeck	fi
7739b0b3b7SJohn Beck	exist_or_exit "$SENDMAIL_CF"
780ea5e3a5Sjjj
79d4660949Sjbeck	$SENDMAIL $MODE -q$QUEUEOPTION$QUEUEINTERVAL $OPTIONS &
800ea5e3a5Sjjj
817c478bd9Sstevel@tonic-gate	#
827c478bd9Sstevel@tonic-gate	# ETRN_HOSTS should be of the form
837c478bd9Sstevel@tonic-gate	# "s1:c1.1,c1.2        s2:c2.1 s3:c3.1,c3.2,c3.3"
847c478bd9Sstevel@tonic-gate	# i.e., white-space separated groups of server:client where
857c478bd9Sstevel@tonic-gate	# client can be one or more comma-separated names; N.B. that
86bbf21555SRichard Lowe	# the :client part is optional; see etrn(8) for details.
877c478bd9Sstevel@tonic-gate	# server is the name of the server to prod; a mail queue run
887c478bd9Sstevel@tonic-gate	# is requested for each client name.  This is comparable to
897c478bd9Sstevel@tonic-gate	# running "/usr/lib/sendmail -qRclient" on the host server.
907c478bd9Sstevel@tonic-gate	#
917c478bd9Sstevel@tonic-gate	# See RFC 1985 for more information.
927c478bd9Sstevel@tonic-gate	#
937c478bd9Sstevel@tonic-gate	for i in $ETRN_HOSTS; do
947c478bd9Sstevel@tonic-gate		SERVER=`echo $i | /usr/bin/sed -e 's/:.*$//'`
957c478bd9Sstevel@tonic-gate		CLIENTS=`echo $i | /usr/bin/sed -n -e 's/,/ /g' \
967c478bd9Sstevel@tonic-gate		    -e '/:/s/^.*://p'`
977c478bd9Sstevel@tonic-gate		/usr/sbin/etrn -b $SERVER $CLIENTS >/dev/null 2>&1 &
987c478bd9Sstevel@tonic-gate	done
997c478bd9Sstevel@tonic-gate
1007c478bd9Sstevel@tonic-gate	if /usr/bin/nawk 'BEGIN{s = 1}
1017c478bd9Sstevel@tonic-gate	    $2 == "/var/mail" && $3 == "nfs" && $4 !~ /actimeo=0/ &&
1027c478bd9Sstevel@tonic-gate	    $4 !~ /noac/{s = 0} END{exit s}' /etc/mnttab; then
1037c478bd9Sstevel@tonic-gate
1047c478bd9Sstevel@tonic-gate		/usr/bin/logger -p mail.crit "$ERRMSG1"
1057c478bd9Sstevel@tonic-gate		/usr/bin/logger -p mail.crit "$ERRMSG2"
1067c478bd9Sstevel@tonic-gate	fi
1077c478bd9Sstevel@tonic-gate	;;
1087c478bd9Sstevel@tonic-gate
1097c478bd9Sstevel@tonic-gate'stop')
1107c478bd9Sstevel@tonic-gate	[ -f $SERVER_PID_FILE ] && check_and_kill $SERVER_PID_FILE
1117c478bd9Sstevel@tonic-gate	# Need to kill the entire service contract to kill all sendmail related
1127c478bd9Sstevel@tonic-gate	# processes
1137c478bd9Sstevel@tonic-gate	smf_kill_contract $2 TERM 1 30
1147c478bd9Sstevel@tonic-gate	ret=$?
1157c478bd9Sstevel@tonic-gate	[ $ret -eq 1 ] && exit 1
1167c478bd9Sstevel@tonic-gate
1177c478bd9Sstevel@tonic-gate	# Since sendmail spawns user processes out of .forward files, it is
1187c478bd9Sstevel@tonic-gate	# possible that some of these are not responding to TERM.  If the
1197c478bd9Sstevel@tonic-gate	# contract did not empty after TERM, move on to KILL.
1207c478bd9Sstevel@tonic-gate	if [ $ret -eq 2 ] ; then
1217c478bd9Sstevel@tonic-gate		smf_kill_contract $2 KILL 1
1227c478bd9Sstevel@tonic-gate	fi
1237c478bd9Sstevel@tonic-gate	;;
1247c478bd9Sstevel@tonic-gate
1257c478bd9Sstevel@tonic-gate*)
1267c478bd9Sstevel@tonic-gate	echo "Usage: $0 { start | stop | refresh }"
1277c478bd9Sstevel@tonic-gate	exit 1
1287c478bd9Sstevel@tonic-gate	;;
1297c478bd9Sstevel@tonic-gateesac
1307c478bd9Sstevel@tonic-gateexit 0
131