xref: /illumos-gate/usr/src/cmd/sendmail/lib/smtp-sendmail (revision da98a436d0e5b73a2027dcb08440a065caa74783)
1#!/sbin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23# Use is subject to license terms.
24
25. /lib/svc/share/smf_include.sh
26. /lib/svc/share/sendmail_include.sh
27
28ERRMSG1='WARNING: /var/mail is NFS-mounted without setting actimeo=0,'
29ERRMSG2='this can cause mailbox locking and access problems.'
30SERVER_PID_FILE="/var/run/sendmail.pid"
31ALIASES_FILE="/etc/mail/aliases"
32SENDMAIL_CF="/etc/mail/sendmail.cf"
33
34case "$1" in
35'refresh')
36        [ -f $SERVER_PID_FILE ] && kill -1 `head -1 $SERVER_PID_FILE`
37        ;;
38
39'start')
40	exist_or_exit $SENDMAIL
41	if [ ! -d /var/spool/mqueue ]; then
42		/usr/bin/mkdir -m 0750 /var/spool/mqueue
43		/usr/bin/chown root:bin /var/spool/mqueue
44	fi
45	if [ ! -f $ALIASES_FILE.db ] && [ ! -f $ALIASES_FILE.dir ] \
46	    && [ ! -f $ALIASES_FILE.pag ]; then
47		/usr/sbin/newaliases
48	fi
49	MODE="-bd"
50	[ -f $DEFAULT_FILE ] && . $DEFAULT_FILE
51	#
52	# * MODE should be "-bd" or null (MODE= or MODE="") or
53	#   left alone.  Anything else and you're on your own.
54	# * QUEUEOPTION should be "p" or null (as above).
55	# * QUEUEINTERVAL should be set to some legal value;
56	#   sanity checks are done below.
57	# * OPTIONS are catch-alls; set with care.
58	#
59	if [ -n "$QUEUEOPTION" -a "$QUEUEOPTION" != "p" ]; then
60		QUEUEOPTION=""
61	fi
62	if [ -z "$QUEUEOPTION" -o -n "$QUEUEINTERVAL" ]; then
63		check_queue_interval_syntax $QUEUEINTERVAL
64		QUEUEINTERVAL=$answer
65	fi
66
67	local=`/usr/bin/svcprop -p config/local_only $SMF_FMRI 2>/dev/null`
68	if [ $? -eq 0 -a "$local" = "true" ]; then
69		MODE="-bl"
70	fi
71	sendmail_path=`svcprop -p config/path_to_sendmail_mc $SMF_FMRI \
72	    2>/dev/null`
73	if [ $? -eq 0 -a -n "$sendmail_path" ]; then
74		turn_m4_crank $SENDMAIL_CF $sendmail_path
75	fi
76	exist_or_exit $SENDMAIL_CF
77
78	$SENDMAIL $MODE -q$QUEUEOPTION$QUEUEINTERVAL $OPTIONS &
79
80	#
81	# ETRN_HOSTS should be of the form
82	# "s1:c1.1,c1.2        s2:c2.1 s3:c3.1,c3.2,c3.3"
83	# i.e., white-space separated groups of server:client where
84	# client can be one or more comma-separated names; N.B. that
85	# the :client part is optional; see etrn(1M) for details.
86	# server is the name of the server to prod; a mail queue run
87	# is requested for each client name.  This is comparable to
88	# running "/usr/lib/sendmail -qRclient" on the host server.
89	#
90	# See RFC 1985 for more information.
91	#
92	for i in $ETRN_HOSTS; do
93		SERVER=`echo $i | /usr/bin/sed -e 's/:.*$//'`
94		CLIENTS=`echo $i | /usr/bin/sed -n -e 's/,/ /g' \
95		    -e '/:/s/^.*://p'`
96		/usr/sbin/etrn -b $SERVER $CLIENTS >/dev/null 2>&1 &
97	done
98
99	if /usr/bin/nawk 'BEGIN{s = 1}
100	    $2 == "/var/mail" && $3 == "nfs" && $4 !~ /actimeo=0/ &&
101	    $4 !~ /noac/{s = 0} END{exit s}' /etc/mnttab; then
102
103		/usr/bin/logger -p mail.crit "$ERRMSG1"
104		/usr/bin/logger -p mail.crit "$ERRMSG2"
105	fi
106	;;
107
108'stop')
109	[ -f $SERVER_PID_FILE ] && check_and_kill $SERVER_PID_FILE
110	# Need to kill the entire service contract to kill all sendmail related
111	# processes
112	smf_kill_contract $2 TERM 1 30
113	ret=$?
114	[ $ret -eq 1 ] && exit 1
115
116	# Since sendmail spawns user processes out of .forward files, it is
117	# possible that some of these are not responding to TERM.  If the
118	# contract did not empty after TERM, move on to KILL.
119	if [ $ret -eq 2 ] ; then
120		smf_kill_contract $2 KILL 1
121	fi
122	;;
123
124*)
125	echo "Usage: $0 { start | stop | refresh }"
126	exit 1
127	;;
128esac
129exit 0
130