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