xref: /illumos-gate/usr/src/cmd/sendmail/lib/smtp-sendmail (revision 2844a23795611c7d7ebc1bee3bdd3e0824c0141e)
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		# Create the aliases database
48		$SENDMAIL -bi
49	fi
50	MODE="-bd"
51	[ -f $DEFAULT_FILE ] && . $DEFAULT_FILE
52	#
53	# * MODE should be "-bd" or null (MODE= or MODE="") or
54	#   left alone.  Anything else and you're on your own.
55	# * QUEUEOPTION should be "p" or null (as above).
56	# * QUEUEINTERVAL should be set to some legal value;
57	#   sanity checks are done below.
58	# * OPTIONS are catch-alls; set with care.
59	#
60	if [ -n "$QUEUEOPTION" -a "$QUEUEOPTION" != "p" ]; then
61		QUEUEOPTION=""
62	fi
63	if [ -z "$QUEUEOPTION" -o -n "$QUEUEINTERVAL" ]; then
64		check_queue_interval_syntax $QUEUEINTERVAL
65		QUEUEINTERVAL=$answer
66	fi
67
68	local=`/usr/bin/svcprop -p config/local_only $SMF_FMRI 2>/dev/null`
69	if [ $? -eq 0 -a "$local" = "true" ]; then
70		MODE="-bl"
71	fi
72	sendmail_path=`svcprop -p config/path_to_sendmail_mc $SMF_FMRI \
73	    2>/dev/null`
74	if [ $? -eq 0 -a -n "$sendmail_path" ]; then
75		turn_m4_crank "$SENDMAIL_CF" "$sendmail_path"
76	fi
77	exist_or_exit "$SENDMAIL_CF"
78
79	$SENDMAIL $MODE -q$QUEUEOPTION$QUEUEINTERVAL $OPTIONS &
80
81	#
82	# ETRN_HOSTS should be of the form
83	# "s1:c1.1,c1.2        s2:c2.1 s3:c3.1,c3.2,c3.3"
84	# i.e., white-space separated groups of server:client where
85	# client can be one or more comma-separated names; N.B. that
86	# the :client part is optional; see etrn(8) for details.
87	# server is the name of the server to prod; a mail queue run
88	# is requested for each client name.  This is comparable to
89	# running "/usr/lib/sendmail -qRclient" on the host server.
90	#
91	# See RFC 1985 for more information.
92	#
93	for i in $ETRN_HOSTS; do
94		SERVER=`echo $i | /usr/bin/sed -e 's/:.*$//'`
95		CLIENTS=`echo $i | /usr/bin/sed -n -e 's/,/ /g' \
96		    -e '/:/s/^.*://p'`
97		/usr/sbin/etrn -b $SERVER $CLIENTS >/dev/null 2>&1 &
98	done
99
100	if /usr/bin/nawk 'BEGIN{s = 1}
101	    $2 == "/var/mail" && $3 == "nfs" && $4 !~ /actimeo=0/ &&
102	    $4 !~ /noac/{s = 0} END{exit s}' /etc/mnttab; then
103
104		/usr/bin/logger -p mail.crit "$ERRMSG1"
105		/usr/bin/logger -p mail.crit "$ERRMSG2"
106	fi
107	;;
108
109'stop')
110	[ -f $SERVER_PID_FILE ] && check_and_kill $SERVER_PID_FILE
111	# Need to kill the entire service contract to kill all sendmail related
112	# processes
113	smf_kill_contract $2 TERM 1 30
114	ret=$?
115	[ $ret -eq 1 ] && exit 1
116
117	# Since sendmail spawns user processes out of .forward files, it is
118	# possible that some of these are not responding to TERM.  If the
119	# contract did not empty after TERM, move on to KILL.
120	if [ $ret -eq 2 ] ; then
121		smf_kill_contract $2 KILL 1
122	fi
123	;;
124
125*)
126	echo "Usage: $0 { start | stop | refresh }"
127	exit 1
128	;;
129esac
130exit 0
131