xref: /dragonfly/etc/rc.sendmail (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1#!/bin/sh
2
3#
4# Copyright (c) 2002  Gregory Neil Shapiro.  All Rights Reserved.
5# Copyright (c) 2000, 2002  The FreeBSD Project
6# All rights reserved.
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27# SUCH DAMAGE.
28#
29# $FreeBSD: src/etc/rc.sendmail,v 1.3.2.1 2002/04/24 17:28:08 gshapiro Exp $
30# $DragonFly: src/etc/rc.sendmail,v 1.3 2005/07/25 00:24:31 gshapiro Exp $
31#
32
33# This script is used by /etc/rc at boot time to start sendmail.  It
34# is meant to be sendmail specific and not a generic script for all
35# MTAs.  It is only called by /etc/rc if the rc.conf mta_start_script is
36# set to /etc/rc.sendmail.  This provides the opportunity for other MTAs
37# to provide their own startup script.
38
39# The script is also used by /etc/mail/Makefile to enable the
40# start/stop/restart targets.
41
42# The source for the script can be found in src/etc/sendmail/rc.sendmail.
43
44if [ -r /etc/defaults/rc.conf ]; then
45          . /etc/defaults/rc.conf
46          source_rc_confs
47elif [ -r /etc/rc.conf ]; then
48          . /etc/rc.conf
49fi
50
51# The sendmail binary
52sendmail_program=${sendmail_program:-/usr/sbin/sendmail}
53
54# The pid is used to stop and restart the running daemon(s).
55sendmail_pidfile=${sendmail_pidfile:-/var/run/sendmail.pid}
56sendmail_mspq_pidfile=${sendmail_mspq_pidfile:-/var/spool/clientmqueue/sm-client.pid}
57
58start_mta()
59{
60          case ${sendmail_enable} in
61          [Nn][Oo][Nn][Ee])
62                    ;;
63          [Yy][Ee][Ss])
64                    echo -n ' sendmail'
65                    ${sendmail_program} ${sendmail_flags}
66                    ;;
67          *)
68                    case ${sendmail_submit_enable} in
69                    [Yy][Ee][Ss])
70                              echo -n ' sendmail-submit'
71                              ${sendmail_program} ${sendmail_submit_flags}
72                              ;;
73                    *)
74                              case ${sendmail_outbound_enable} in
75                              [Yy][Ee][Ss])
76                                        echo -n ' sendmail-outbound'
77                                        ${sendmail_program} ${sendmail_outbound_flags}
78                                        ;;
79                              esac
80                              ;;
81                    esac
82                    ;;
83          esac
84}
85
86stop_mta()
87{
88          # Check to make sure we are configured to start an MTA
89          case ${sendmail_enable} in
90          [Nn][Oo][Nn][Ee])
91                    return
92                    ;;
93          [Yy][Ee][Ss])
94                    ;;
95          *)
96                    case ${sendmail_submit_enable} in
97                    [Yy][Ee][Ss])
98                              ;;
99                    *)
100                              case ${sendmail_outbound_enable} in
101                              [Yy][Ee][Ss])
102                                        ;;
103                              *)
104                                        return
105                                        ;;
106                              esac
107                              ;;
108                    esac
109                    ;;
110          esac
111
112          if [ -r ${sendmail_pidfile} ]; then
113                    echo -n ' sendmail'
114                    kill -TERM `head -1 ${sendmail_pidfile}`
115          else
116                    echo "$0: stop-mta: ${sendmail_pidfile} not found"
117          fi
118}
119
120restart_mta()
121{
122          # Check to make sure we are configured to start an MTA
123          case ${sendmail_enable} in
124          [Nn][Oo][Nn][Ee])
125                    return
126                    ;;
127          [Yy][Ee][Ss])
128                    ;;
129          *)
130                    case ${sendmail_submit_enable} in
131                    [Yy][Ee][Ss])
132                              ;;
133                    *)
134                              case ${sendmail_outbound_enable} in
135                              [Yy][Ee][Ss])
136                                        ;;
137                              *)
138                                        return
139                                        ;;
140                              esac
141                              ;;
142                    esac
143                    ;;
144          esac
145
146          if [ -r ${sendmail_pidfile} ]; then
147                    echo -n ' sendmail'
148                    kill -HUP `head -1 ${sendmail_pidfile}`
149          else
150                    echo "$0: restart-mta: ${sendmail_pidfile} not found"
151          fi
152}
153
154start_mspq()
155{
156          case ${sendmail_enable} in
157          [Nn][Oo][Nn][Ee])
158                    ;;
159          *)
160                    if [ -r /etc/mail/submit.cf ]; then
161                              case ${sendmail_msp_queue_enable} in
162                              [Yy][Ee][Ss])
163                                        echo -n ' sendmail-clientmqueue'
164                                        ${sendmail_program} ${sendmail_msp_queue_flags}
165                                        ;;
166                              esac
167                    fi
168                    ;;
169          esac
170}
171
172stop_mspq()
173{
174          # Check to make sure we are configured to start an MSP queue runner
175          case ${sendmail_enable} in
176          [Nn][Oo][Nn][Ee])
177                    return
178                    ;;
179          *)
180                    if [ -r /etc/mail/submit.cf ]; then
181                              case ${sendmail_msp_queue_enable} in
182                              [Yy][Ee][Ss])
183                                        ;;
184                              *)
185                                        return
186                                        ;;
187                              esac
188                    fi
189                    ;;
190          esac
191
192          if [ -r ${sendmail_mspq_pidfile} ]; then
193                    echo -n ' sendmail-clientmqueue'
194                    kill -TERM `head -1 ${sendmail_mspq_pidfile}`
195          else
196                    echo "$0: stop-mspq: ${sendmail_mspq_pidfile} not found"
197          fi
198}
199
200restart_mspq()
201{
202          # Check to make sure we are configured to start an MSP queue runner
203          case ${sendmail_enable} in
204          [Nn][Oo][Nn][Ee])
205                    return
206                    ;;
207          *)
208                    if [ -r /etc/mail/submit.cf ]; then
209                              case ${sendmail_msp_queue_enable} in
210                              [Yy][Ee][Ss])
211                                        ;;
212                              *)
213                                        return
214                                        ;;
215                              esac
216                    fi
217                    ;;
218          esac
219
220          if [ -r ${sendmail_mspq_pidfile} ]; then
221                    echo -n ' sendmail-clientmqueue'
222                    kill -HUP `head -1 ${sendmail_mspq_pidfile}`
223          else
224                    echo "$0: restart-mspq: ${sendmail_mspq_pidfile} not found"
225          fi
226}
227
228# If no argument is given, assume we are being called at boot time.
229_action=${1:-start}
230
231case ${_action} in
232start)
233          start_mta
234          start_mspq
235          ;;
236
237stop)
238          stop_mta
239          stop_mspq
240          ;;
241
242restart)
243          restart_mta
244          restart_mspq
245          ;;
246
247start-mta)
248          start_mta
249          ;;
250
251stop-mta)
252          stop_mta
253          ;;
254
255restart-mta)
256          restart_mta
257          ;;
258
259start-mspq)
260          start_mspq
261          ;;
262
263stop-mspq)
264          stop_mspq
265          ;;
266
267restart-mspq)
268          restart_mspq
269          ;;
270
271*)
272          echo "Usage: `basename $0` {start|stop|restart}" >&2
273          echo "       `basename $0` {start-mta|stop-mta|restart-mta}" >&2
274          echo "       `basename $0` {start-mspq|stop-mspq|restart-mspq}" >&2
275          exit 64
276          ;;
277
278esac
279exit 0
280