rc.sendmail revision 114522
1114522Sdougb#!/bin/sh
2114522Sdougb
3114522Sdougb#
4114522Sdougb# Copyright (c) 2002  Gregory Neil Shapiro.  All Rights Reserved.
5114522Sdougb# Copyright (c) 2000, 2002  The FreeBSD Project
6114522Sdougb# All rights reserved.
7114522Sdougb#
8114522Sdougb# Redistribution and use in source and binary forms, with or without
9114522Sdougb# modification, are permitted provided that the following conditions
10114522Sdougb# are met:
11114522Sdougb# 1. Redistributions of source code must retain the above copyright
12114522Sdougb#    notice, this list of conditions and the following disclaimer.
13114522Sdougb# 2. Redistributions in binary form must reproduce the above copyright
14114522Sdougb#    notice, this list of conditions and the following disclaimer in the
15114522Sdougb#    documentation and/or other materials provided with the distribution.
16114522Sdougb#
17114522Sdougb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18114522Sdougb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19114522Sdougb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20114522Sdougb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21114522Sdougb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22114522Sdougb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23114522Sdougb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24114522Sdougb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25114522Sdougb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26114522Sdougb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27114522Sdougb# SUCH DAMAGE.
28114522Sdougb#
29114522Sdougb# $FreeBSD: head/etc/rc.sendmail 114522 2003-05-02 11:05:57Z dougb $
30114522Sdougb#
31114522Sdougb
32114522Sdougb# This script is used by /etc/rc at boot time to start sendmail.  It
33114522Sdougb# is meant to be sendmail specific and not a generic script for all
34114522Sdougb# MTAs.  It is only called by /etc/rc if the rc.conf mta_start_script is
35114522Sdougb# set to /etc/rc.sendmail.  This provides the opportunity for other MTAs
36114522Sdougb# to provide their own startup script.
37114522Sdougb
38114522Sdougb# The script is also used by /etc/mail/Makefile to enable the
39114522Sdougb# start/stop/restart targets.
40114522Sdougb
41114522Sdougb# The source for the script can be found in src/etc/sendmail/rc.sendmail.
42114522Sdougb
43114522Sdougbif [ -r /etc/defaults/rc.conf ]; then
44114522Sdougb	. /etc/defaults/rc.conf
45114522Sdougb	source_rc_confs
46114522Sdougbelif [ -r /etc/rc.conf ]; then
47114522Sdougb	. /etc/rc.conf
48114522Sdougbfi
49114522Sdougb
50114522Sdougb# The sendmail binary
51114522Sdougbsendmail_program=${sendmail_program:-/usr/sbin/sendmail}
52114522Sdougb
53114522Sdougb# The pid is used to stop and restart the running daemon(s).
54114522Sdougbsendmail_pidfile=${sendmail_pidfile:-/var/run/sendmail.pid}
55114522Sdougbsendmail_mspq_pidfile=${sendmail_mspq_pidfile:-/var/spool/clientmqueue/sm-client.pid}
56114522Sdougb
57114522Sdougbstart_mta()
58114522Sdougb{
59114522Sdougb	case ${sendmail_enable} in
60114522Sdougb	[Nn][Oo][Nn][Ee])
61114522Sdougb		;;
62114522Sdougb	[Yy][Ee][Ss])
63114522Sdougb		echo -n ' sendmail'
64114522Sdougb		${sendmail_program} ${sendmail_flags}
65114522Sdougb		;;
66114522Sdougb	*)
67114522Sdougb		case ${sendmail_submit_enable} in
68114522Sdougb		[Yy][Ee][Ss])
69114522Sdougb			echo -n ' sendmail-submit'
70114522Sdougb			${sendmail_program} ${sendmail_submit_flags}
71114522Sdougb			;;
72114522Sdougb		*)
73114522Sdougb			case ${sendmail_outbound_enable} in
74114522Sdougb			[Yy][Ee][Ss])
75114522Sdougb				echo -n ' sendmail-outbound'
76114522Sdougb				${sendmail_program} ${sendmail_outbound_flags}
77114522Sdougb				;;
78114522Sdougb			esac
79114522Sdougb			;;
80114522Sdougb		esac
81114522Sdougb		;;
82114522Sdougb	esac
83114522Sdougb}
84114522Sdougb
85114522Sdougbstop_mta()
86114522Sdougb{
87114522Sdougb	if [ -r ${sendmail_pidfile} ]; then
88114522Sdougb		echo -n ' sendmail'
89114522Sdougb		kill -TERM `head -1 ${sendmail_pidfile}`
90114522Sdougb	else
91114522Sdougb		echo "$0: stop-mta: ${sendmail_pidfile} not found"
92114522Sdougb	fi
93114522Sdougb}
94114522Sdougb
95114522Sdougbrestart_mta()
96114522Sdougb{
97114522Sdougb	if [ -r ${sendmail_pidfile} ]; then
98114522Sdougb		echo -n ' sendmail'
99114522Sdougb		kill -HUP `head -1 ${sendmail_pidfile}`
100114522Sdougb	else
101114522Sdougb		echo "$0: restart-mta: ${sendmail_pidfile} not found"
102114522Sdougb	fi
103114522Sdougb}
104114522Sdougb
105114522Sdougbstart_mspq()
106114522Sdougb{
107114522Sdougb	case ${sendmail_enable} in
108114522Sdougb	[Nn][Oo][Nn][Ee])
109114522Sdougb		;;
110114522Sdougb	*)
111114522Sdougb		if [ -r /etc/mail/submit.cf ]; then
112114522Sdougb			case ${sendmail_msp_queue_enable} in
113114522Sdougb			[Yy][Ee][Ss])
114114522Sdougb				echo -n ' sendmail-clientmqueue'
115114522Sdougb				${sendmail_program} ${sendmail_msp_queue_flags}
116114522Sdougb				;;
117114522Sdougb			esac
118114522Sdougb		fi
119114522Sdougb		;;
120114522Sdougb	esac
121114522Sdougb}
122114522Sdougb
123114522Sdougbstop_mspq()
124114522Sdougb{
125114522Sdougb	if [ -r ${sendmail_mspq_pidfile} ]; then
126114522Sdougb		echo -n ' sendmail-clientmqueue'
127114522Sdougb		kill -TERM `head -1 ${sendmail_mspq_pidfile}`
128114522Sdougb	else
129114522Sdougb		echo "$0: stop-mspq: ${sendmail_mspq_pidfile} not found"
130114522Sdougb	fi
131114522Sdougb}
132114522Sdougb
133114522Sdougbrestart_mspq()
134114522Sdougb{
135114522Sdougb	if [ -r ${sendmail_mspq_pidfile} ]; then
136114522Sdougb		echo -n ' sendmail-clientmqueue'
137114522Sdougb		kill -HUP `head -1 ${sendmail_mspq_pidfile}`
138114522Sdougb	else
139114522Sdougb		echo "$0: restart-mspq: ${sendmail_mspq_pidfile} not found"
140114522Sdougb	fi
141114522Sdougb}
142114522Sdougb
143114522Sdougb# If no argument is given, assume we are being called at boot time.
144114522Sdougb_action=${1:-start}
145114522Sdougb
146114522Sdougbcase ${_action} in
147114522Sdougbstart)
148114522Sdougb	start_mta
149114522Sdougb	start_mspq
150114522Sdougb	;;
151114522Sdougb
152114522Sdougbstop)
153114522Sdougb	stop_mta
154114522Sdougb	stop_mspq
155114522Sdougb	;;
156114522Sdougb
157114522Sdougbrestart)
158114522Sdougb	restart_mta
159114522Sdougb	restart_mspq
160114522Sdougb	;;
161114522Sdougb
162114522Sdougbstart-mta)
163114522Sdougb	start_mta
164114522Sdougb	;;
165114522Sdougb
166114522Sdougbstop-mta)
167114522Sdougb	stop_mta
168114522Sdougb	;;
169114522Sdougb
170114522Sdougbrestart-mta)
171114522Sdougb	restart_mta
172114522Sdougb	;;
173114522Sdougb
174114522Sdougbstart-mspq)
175114522Sdougb	start_mspq
176114522Sdougb	;;
177114522Sdougb
178114522Sdougbstop-mspq)
179114522Sdougb	stop_mspq
180114522Sdougb	;;
181114522Sdougb
182114522Sdougbrestart-mspq)
183114522Sdougb	restart_mspq
184114522Sdougb	;;
185114522Sdougb
186114522Sdougb*)
187114522Sdougb	echo "usage: `basename $0` {start|stop|restart}" >&2
188114522Sdougb	echo "       `basename $0` {start-mta|stop-mta|restart-mta}" >&2
189114522Sdougb	echo "       `basename $0` {start-mspq|stop-mspq|restart-mspq}" >&2
190114522Sdougb	exit 64
191114522Sdougb	;;
192114522Sdougb
193114522Sdougbesac
194114522Sdougbexit 0
195