rc.sendmail revision 114522
1155312Swsalamon#!/bin/sh
2155312Swsalamon
3155312Swsalamon#
4155312Swsalamon# Copyright (c) 2002  Gregory Neil Shapiro.  All Rights Reserved.
5155312Swsalamon# Copyright (c) 2000, 2002  The FreeBSD Project
6155312Swsalamon# All rights reserved.
7155312Swsalamon#
8155312Swsalamon# Redistribution and use in source and binary forms, with or without
9155312Swsalamon# modification, are permitted provided that the following conditions
10155312Swsalamon# are met:
11155312Swsalamon# 1. Redistributions of source code must retain the above copyright
12155312Swsalamon#    notice, this list of conditions and the following disclaimer.
13155312Swsalamon# 2. Redistributions in binary form must reproduce the above copyright
14155312Swsalamon#    notice, this list of conditions and the following disclaimer in the
15155312Swsalamon#    documentation and/or other materials provided with the distribution.
16155312Swsalamon#
17155312Swsalamon# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18155312Swsalamon# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19155312Swsalamon# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20155312Swsalamon# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21155312Swsalamon# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22155312Swsalamon# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23155312Swsalamon# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24155312Swsalamon# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25155312Swsalamon# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26155312Swsalamon# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27155312Swsalamon# SUCH DAMAGE.
28155312Swsalamon#
29155312Swsalamon# $FreeBSD: head/etc/rc.sendmail 114522 2003-05-02 11:05:57Z dougb $
30155312Swsalamon#
31155312Swsalamon
32155312Swsalamon# This script is used by /etc/rc at boot time to start sendmail.  It
33155312Swsalamon# is meant to be sendmail specific and not a generic script for all
34155312Swsalamon# MTAs.  It is only called by /etc/rc if the rc.conf mta_start_script is
35155312Swsalamon# set to /etc/rc.sendmail.  This provides the opportunity for other MTAs
36155312Swsalamon# to provide their own startup script.
37155312Swsalamon
38155312Swsalamon# The script is also used by /etc/mail/Makefile to enable the
39155312Swsalamon# start/stop/restart targets.
40155312Swsalamon
41155312Swsalamon# The source for the script can be found in src/etc/sendmail/rc.sendmail.
42155312Swsalamon
43155312Swsalamonif [ -r /etc/defaults/rc.conf ]; then
44155312Swsalamon	. /etc/defaults/rc.conf
45155312Swsalamon	source_rc_confs
46169342Sdwmaloneelif [ -r /etc/rc.conf ]; then
47169342Sdwmalone	. /etc/rc.conf
48155312Swsalamonfi
49155312Swsalamon
50155312Swsalamon# The sendmail binary
51155312Swsalamonsendmail_program=${sendmail_program:-/usr/sbin/sendmail}
52155312Swsalamon
53155312Swsalamon# The pid is used to stop and restart the running daemon(s).
54155312Swsalamonsendmail_pidfile=${sendmail_pidfile:-/var/run/sendmail.pid}
55155312Swsalamonsendmail_mspq_pidfile=${sendmail_mspq_pidfile:-/var/spool/clientmqueue/sm-client.pid}
56155312Swsalamon
57155312Swsalamonstart_mta()
58155312Swsalamon{
59155312Swsalamon	case ${sendmail_enable} in
60155312Swsalamon	[Nn][Oo][Nn][Ee])
61155312Swsalamon		;;
62155312Swsalamon	[Yy][Ee][Ss])
63155312Swsalamon		echo -n ' sendmail'
64155312Swsalamon		${sendmail_program} ${sendmail_flags}
65155312Swsalamon		;;
66155312Swsalamon	*)
67155312Swsalamon		case ${sendmail_submit_enable} in
68155312Swsalamon		[Yy][Ee][Ss])
69155312Swsalamon			echo -n ' sendmail-submit'
70191297Srwatson			${sendmail_program} ${sendmail_submit_flags}
71155312Swsalamon			;;
72155312Swsalamon		*)
73191297Srwatson			case ${sendmail_outbound_enable} in
74155312Swsalamon			[Yy][Ee][Ss])
75155312Swsalamon				echo -n ' sendmail-outbound'
76155312Swsalamon				${sendmail_program} ${sendmail_outbound_flags}
77155312Swsalamon				;;
78155312Swsalamon			esac
79155312Swsalamon			;;
80155312Swsalamon		esac
81155312Swsalamon		;;
82155312Swsalamon	esac
83155312Swsalamon}
84155312Swsalamon
85155312Swsalamonstop_mta()
86155312Swsalamon{
87155312Swsalamon	if [ -r ${sendmail_pidfile} ]; then
88155312Swsalamon		echo -n ' sendmail'
89155312Swsalamon		kill -TERM `head -1 ${sendmail_pidfile}`
90155312Swsalamon	else
91155312Swsalamon		echo "$0: stop-mta: ${sendmail_pidfile} not found"
92155312Swsalamon	fi
93155312Swsalamon}
94155312Swsalamon
95155312Swsalamonrestart_mta()
96155312Swsalamon{
97155312Swsalamon	if [ -r ${sendmail_pidfile} ]; then
98155312Swsalamon		echo -n ' sendmail'
99155312Swsalamon		kill -HUP `head -1 ${sendmail_pidfile}`
100155312Swsalamon	else
101155312Swsalamon		echo "$0: restart-mta: ${sendmail_pidfile} not found"
102155312Swsalamon	fi
103155312Swsalamon}
104155312Swsalamon
105155312Swsalamonstart_mspq()
106155312Swsalamon{
107155312Swsalamon	case ${sendmail_enable} in
108155312Swsalamon	[Nn][Oo][Nn][Ee])
109155312Swsalamon		;;
110155312Swsalamon	*)
111155312Swsalamon		if [ -r /etc/mail/submit.cf ]; then
112155312Swsalamon			case ${sendmail_msp_queue_enable} in
113155312Swsalamon			[Yy][Ee][Ss])
114169342Sdwmalone				echo -n ' sendmail-clientmqueue'
115155312Swsalamon				${sendmail_program} ${sendmail_msp_queue_flags}
116155312Swsalamon				;;
117155312Swsalamon			esac
118191297Srwatson		fi
119155312Swsalamon		;;
120155312Swsalamon	esac
121155312Swsalamon}
122155312Swsalamon
123155312Swsalamonstop_mspq()
124191297Srwatson{
125155312Swsalamon	if [ -r ${sendmail_mspq_pidfile} ]; then
126155312Swsalamon		echo -n ' sendmail-clientmqueue'
127155312Swsalamon		kill -TERM `head -1 ${sendmail_mspq_pidfile}`
128155312Swsalamon	else
129155312Swsalamon		echo "$0: stop-mspq: ${sendmail_mspq_pidfile} not found"
130155312Swsalamon	fi
131155312Swsalamon}
132155312Swsalamon
133155312Swsalamonrestart_mspq()
134155312Swsalamon{
135155312Swsalamon	if [ -r ${sendmail_mspq_pidfile} ]; then
136155312Swsalamon		echo -n ' sendmail-clientmqueue'
137155312Swsalamon		kill -HUP `head -1 ${sendmail_mspq_pidfile}`
138155312Swsalamon	else
139155312Swsalamon		echo "$0: restart-mspq: ${sendmail_mspq_pidfile} not found"
140155312Swsalamon	fi
141155312Swsalamon}
142155312Swsalamon
143155312Swsalamon# If no argument is given, assume we are being called at boot time.
144155312Swsalamon_action=${1:-start}
145155312Swsalamon
146155312Swsalamoncase ${_action} in
147155312Swsalamonstart)
148155312Swsalamon	start_mta
149155312Swsalamon	start_mspq
150155312Swsalamon	;;
151155312Swsalamon
152155312Swsalamonstop)
153155312Swsalamon	stop_mta
154155312Swsalamon	stop_mspq
155155312Swsalamon	;;
156155312Swsalamon
157155312Swsalamonrestart)
158155312Swsalamon	restart_mta
159155312Swsalamon	restart_mspq
160155312Swsalamon	;;
161155312Swsalamon
162155312Swsalamonstart-mta)
163155312Swsalamon	start_mta
164155312Swsalamon	;;
165155312Swsalamon
166155312Swsalamonstop-mta)
167155312Swsalamon	stop_mta
168155312Swsalamon	;;
169155312Swsalamon
170155312Swsalamonrestart-mta)
171155312Swsalamon	restart_mta
172155312Swsalamon	;;
173155312Swsalamon
174155312Swsalamonstart-mspq)
175155312Swsalamon	start_mspq
176155312Swsalamon	;;
177155312Swsalamon
178191297Srwatsonstop-mspq)
179155312Swsalamon	stop_mspq
180155312Swsalamon	;;
181191297Srwatson
182155312Swsalamonrestart-mspq)
183155312Swsalamon	restart_mspq
184155312Swsalamon	;;
185155312Swsalamon
186155312Swsalamon*)
187155312Swsalamon	echo "usage: `basename $0` {start|stop|restart}" >&2
188155312Swsalamon	echo "       `basename $0` {start-mta|stop-mta|restart-mta}" >&2
189155312Swsalamon	echo "       `basename $0` {start-mspq|stop-mspq|restart-mspq}" >&2
190155312Swsalamon	exit 64
191155312Swsalamon	;;
192155312Swsalamon
193155312Swsalamonesac
194155312Swsalamonexit 0
195155312Swsalamon