xref: /onnv-gate/usr/src/cmd/sendmail/lib/sendmail-client (revision 8838:34309a33d6f4)
1*8838SJohn.Beck@Sun.COM#!/sbin/sh
2*8838SJohn.Beck@Sun.COM#
3*8838SJohn.Beck@Sun.COM# CDDL HEADER START
4*8838SJohn.Beck@Sun.COM#
5*8838SJohn.Beck@Sun.COM# The contents of this file are subject to the terms of the
6*8838SJohn.Beck@Sun.COM# Common Development and Distribution License (the "License").
7*8838SJohn.Beck@Sun.COM# You may not use this file except in compliance with the License.
8*8838SJohn.Beck@Sun.COM#
9*8838SJohn.Beck@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*8838SJohn.Beck@Sun.COM# or http://www.opensolaris.org/os/licensing.
11*8838SJohn.Beck@Sun.COM# See the License for the specific language governing permissions
12*8838SJohn.Beck@Sun.COM# and limitations under the License.
13*8838SJohn.Beck@Sun.COM#
14*8838SJohn.Beck@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each
15*8838SJohn.Beck@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*8838SJohn.Beck@Sun.COM# If applicable, add the following below this CDDL HEADER, with the
17*8838SJohn.Beck@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying
18*8838SJohn.Beck@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner]
19*8838SJohn.Beck@Sun.COM#
20*8838SJohn.Beck@Sun.COM# CDDL HEADER END
21*8838SJohn.Beck@Sun.COM#
22*8838SJohn.Beck@Sun.COM# Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23*8838SJohn.Beck@Sun.COM# Use is subject to license terms.
24*8838SJohn.Beck@Sun.COM
25*8838SJohn.Beck@Sun.COM. /lib/svc/share/smf_include.sh
26*8838SJohn.Beck@Sun.COM. /lib/svc/share/sendmail_include.sh
27*8838SJohn.Beck@Sun.COM
28*8838SJohn.Beck@Sun.COMCLIENT_PID_FILE="/var/spool/clientmqueue/sm-client.pid"
29*8838SJohn.Beck@Sun.COMSUBMIT_CF="/etc/mail/submit.cf"
30*8838SJohn.Beck@Sun.COM
31*8838SJohn.Beck@Sun.COMcase "$1" in
32*8838SJohn.Beck@Sun.COM'refresh')
33*8838SJohn.Beck@Sun.COM        [ -f $CLIENT_PID_FILE ] && kill -1 `head -1 $CLIENT_PID_FILE`
34*8838SJohn.Beck@Sun.COM        ;;
35*8838SJohn.Beck@Sun.COM
36*8838SJohn.Beck@Sun.COM'start')
37*8838SJohn.Beck@Sun.COM	exist_or_exit $SENDMAIL
38*8838SJohn.Beck@Sun.COM	[ -f $DEFAULT_FILE ] && . $DEFAULT_FILE
39*8838SJohn.Beck@Sun.COM	#
40*8838SJohn.Beck@Sun.COM	# * CLIENTQUEUEINTERVAL should be set to some legal value;
41*8838SJohn.Beck@Sun.COM	#   sanity checks are done below.
42*8838SJohn.Beck@Sun.COM	# * CLIENTOPTIONS are catch-alls; set with care.
43*8838SJohn.Beck@Sun.COM	#
44*8838SJohn.Beck@Sun.COM	check_queue_interval_syntax $CLIENTQUEUEINTERVAL
45*8838SJohn.Beck@Sun.COM	CLIENTQUEUEINTERVAL=$answer
46*8838SJohn.Beck@Sun.COM
47*8838SJohn.Beck@Sun.COM	submit_path=`svcprop -p config/path_to_submit_mc $SMF_FMRI 2>/dev/null`
48*8838SJohn.Beck@Sun.COM	if [ $? -eq 0 -a -n "$submit_path" ]; then
49*8838SJohn.Beck@Sun.COM		turn_m4_crank $SUBMIT_CF $submit_path
50*8838SJohn.Beck@Sun.COM	fi
51*8838SJohn.Beck@Sun.COM	exist_or_exit $SUBMIT_CF
52*8838SJohn.Beck@Sun.COM
53*8838SJohn.Beck@Sun.COM	$SENDMAIL -Ac -q$CLIENTQUEUEINTERVAL $CLIENTOPTIONS &
54*8838SJohn.Beck@Sun.COM	;;
55*8838SJohn.Beck@Sun.COM
56*8838SJohn.Beck@Sun.COM'stop')
57*8838SJohn.Beck@Sun.COM	if [ -f $CLIENT_PID_FILE ]; then
58*8838SJohn.Beck@Sun.COM		check_and_kill $CLIENT_PID_FILE
59*8838SJohn.Beck@Sun.COM		rm -f $CLIENT_PID_FILE
60*8838SJohn.Beck@Sun.COM	fi
61*8838SJohn.Beck@Sun.COM	# Need to kill the entire service contract to kill all sendmail related
62*8838SJohn.Beck@Sun.COM	# processes
63*8838SJohn.Beck@Sun.COM	smf_kill_contract $2 TERM 1 30
64*8838SJohn.Beck@Sun.COM	ret=$?
65*8838SJohn.Beck@Sun.COM	[ $ret -eq 1 ] && exit 1
66*8838SJohn.Beck@Sun.COM
67*8838SJohn.Beck@Sun.COM	# Sendmail can take its time responding to SIGTERM, as it waits for
68*8838SJohn.Beck@Sun.COM	# things like child processes and SMTP connections to clean up.  If
69*8838SJohn.Beck@Sun.COM	# the contract did not empty after TERM, move on to KILL.
70*8838SJohn.Beck@Sun.COM	if [ $ret -eq 2 ] ; then
71*8838SJohn.Beck@Sun.COM		smf_kill_contract $2 KILL 1
72*8838SJohn.Beck@Sun.COM	fi
73*8838SJohn.Beck@Sun.COM	;;
74*8838SJohn.Beck@Sun.COM
75*8838SJohn.Beck@Sun.COM*)
76*8838SJohn.Beck@Sun.COM	echo "Usage: $0 { start | stop | refresh }"
77*8838SJohn.Beck@Sun.COM	exit 1
78*8838SJohn.Beck@Sun.COM	;;
79*8838SJohn.Beck@Sun.COMesac
80*8838SJohn.Beck@Sun.COMexit 0
81