Import Debian changes 4.92-8+deb10u4
[hcoop/debian/exim4.git] / debian / exim4-base.exim4.init
CommitLineData
de45f55a
AM
1#! /bin/sh
2# /etc/init.d/exim4
3#
4# Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
5# Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
6# Modified for exim by Tim Cutts <timc@chiark.greenend.org.uk>
0baa7b9d 7# Modified for exim4 by Andreas Metzler <ametzler@debian.org>
de45f55a
AM
8# and Marc Haber <mh+debian-packages@zugschlus.de>
9
10### BEGIN INIT INFO
11# Provides: exim4
12# Required-Start: $remote_fs $syslog $named $network $time
13# Required-Stop: $remote_fs $syslog $named $network
14# Should-Start: postgresql mysql clamav-daemon greylist spamassassin
15# Should-Stop: postgresql mysql clamav-daemon greylist spamassassin
16# Default-Start: 2 3 4 5
17# Default-Stop: 0 1 6
18# Short-Description: exim Mail Transport Agent
19# Description: exim is a Mail Transport agent
20### END INIT INFO
21
22set -e
23
24test -x /usr/lib/exim4/exim4 || exit 0
25
26. /lib/lsb/init-functions
27
28if [ -n "$EX4DEBUG" ]; then
29 echo "now debugging $0 $@"
30 set -x
31fi
32
33LANG=C
34export LANG
35
36#read default file
37QUEUERUNNER='combined'
38QUEUEINTERVAL='30m'
39UPEX4OPTS=''
de45f55a 40[ -f /etc/default/exim4 ] && . /etc/default/exim4
0baa7b9d
SB
41PIDFILE="/run/exim4/exim.pid"
42QRPIDFILE="/run/exim4/eximqr.pid"
de45f55a
AM
43
44upex4conf() {
45 UPEX4CONF="update-exim4.conf"
46 OLDIFS="$IFS"
47 IFS=:
48 for p in $PATH; do
49 if [ -x "$p/$UPEX4CONF" ]; then
50 IFS="$OLDIFS"
0baa7b9d 51 $p/$UPEX4CONF $UPEX4OPTS $1
de45f55a
AM
52 return 0
53 fi
54 done
55 IFS="$OLDIFS"
56}
57
58# Exit if exim runs from /etc/inetd.conf
59if [ -f /etc/inetd.conf ] && grep -E -q '^[[:space:]]*((\*|[[:alnum:].-]+):)?smtp[[:space:]]' /etc/inetd.conf
60then
61 upex4conf
62 exit 0
63fi
64
65
66DAEMON="/usr/sbin/exim4"
67NAME="exim4"
68
69# this is from madduck on IRC, 2006-07-06
70# There should be a better possibility to give daemon error messages
71# and/or to log things
72log()
73{
74 case "$1" in
75 [[:digit:]]*) success=$1; shift;;
76 *) :;;
77 esac
78 log_action_begin_msg "$1"; shift
79 log_action_end_msg ${success:-0} "$*"
80}
81
82start_exim()
83{
0baa7b9d
SB
84 [ -e /run/exim4 ] || \
85 install -d -oDebian-exim -gDebian-exim -m750 /run/exim4
de45f55a
AM
86 case ${QUEUERUNNER} in
87 combined)
88 start_daemon -p "$PIDFILE" \
89 "$DAEMON" -bd "-q${QFLAGS}${QUEUEINTERVAL}" \
90 ${COMMONOPTIONS} \
91 ${QUEUERUNNEROPTIONS} \
92 ${SMTPLISTENEROPTIONS}
93 log_progress_msg "exim4"
94 ;;
95 separate)
96 start_daemon -p "$PIDFILE" \
97 "$DAEMON" -bd \
98 ${COMMONOPTIONS} \
99 ${SMTPLISTENEROPTIONS}
100 log_progress_msg "exim4_listener"
101 start_daemon -p "$QRPIDFILE" \
102 "$DAEMON" -oP $QRPIDFILE \
103 "-q${QFLAGS}${QUEUEINTERVAL}" \
104 ${COMMONOPTIONS} \
105 ${QUEUERUNNEROPTIONS}
106 log_progress_msg "exim4_queuerunner"
107 ;;
108 queueonly)
0baa7b9d
SB
109 start_daemon -p "$PIDFILE" \
110 "$DAEMON" -oP $PIDFILE \
de45f55a
AM
111 "-q${QFLAGS}${QUEUEINTERVAL}" \
112 ${COMMONOPTIONS} \
113 ${QUEUERUNNEROPTIONS}
114 log_progress_msg "exim4_queuerunner"
115 ;;
116 no|ppp)
117 start_daemon -p "$PIDFILE" \
118 "$DAEMON" -bd \
119 ${COMMONOPTIONS} \
120 ${SMTPLISTENEROPTIONS}
121 log_progress_msg "exim4_listener"
122 ;;
123 nodaemon)
124 ;;
125 esac
126}
127
128stop_exim()
129{
130# we try to kill eximqr and exim SMTP listener, no matter what
131# ${QUEUERUNNER} is set to, we could have switched since starting.
132 if [ -f "$QRPIDFILE" ]; then
01e60269
AM
133 start-stop-daemon --stop --retry 5 --quiet --oknodo --remove-pidfile \
134 --pidfile "$QRPIDFILE" \
135 --exec "$DAEMON"
de45f55a 136 # exim does not remove the pidfile
01e60269 137 if [ $? -eq 2 ] ; then rm -f "$QRPIDFILE" ; fi
de45f55a
AM
138 log_progress_msg "exim4_queuerunner"
139 fi
140 if [ -f "$PIDFILE" ]; then
01e60269
AM
141 start-stop-daemon --stop --retry 5 --quiet --oknodo --remove-pidfile \
142 --pidfile "$PIDFILE" \
143 --exec "$DAEMON"
de45f55a 144 # exim does not remove the pidfile
01e60269 145 if [ $? -eq 2 ] ; then rm -f "$PIDFILE" ; fi
de45f55a
AM
146 log_progress_msg "exim4_listener"
147 fi
148}
149
150reload_exim()
151{
152 case ${QUEUERUNNER} in
0baa7b9d 153 combined|no|ppp|queueonly)
01e60269
AM
154 start-stop-daemon --stop --signal HUP --quiet --oknodo \
155 --pidfile "$PIDFILE" \
156 --exec "$DAEMON"
de45f55a
AM
157 log_progress_msg "exim4"
158 ;;
159 separate)
01e60269
AM
160 start-stop-daemon --stop --signal HUP --quiet --oknodo \
161 --pidfile "$PIDFILE" \
162 --exec "$DAEMON"
de45f55a 163 log_progress_msg "exim4_listener"
01e60269
AM
164 start-stop-daemon --stop --signal HUP --quiet --oknodo \
165 --pidfile "$QRPIDFILE" \
166 --exec "$DAEMON"
de45f55a
AM
167 log_progress_msg "exim4_queuerunner"
168 ;;
169 esac
170}
171
172kill_all_exims()
173{ SIG="${1:-TERM}"
174 for pid in $(pidof $NAME); do
175 if [ "$(readlink /proc/$pid/root)" = "/" ]; then
176 kill -$SIG $pid
177 fi
178 done
179}
180
181status()
182{
183 # the exit value of this function reflects the status of the SMTP
184 # service. Output shows the status of the queue runner as well.
185 SMTPNAME="SMTP listener daemon"
186 QRNAME="separate queue runner daemon"
187 if [ "${QUEUERUNNER}" = "combined" ]; then
188 SMTPNAME="combined SMTP listener and queue runner daemon"
0baa7b9d
SB
189 elif [ "${QUEUERUNNER}" = "queueonly" ]; then
190 SMTPNAME="separate queue runner daemon"
de45f55a
AM
191 fi
192 log_action_begin_msg "checking $QRNAME"
193 if pidofproc -p "$QRPIDFILE" "$DAEMON" >/dev/null; then
194 log_action_end_msg 0 "running"
195 else
196 if [ -e "$QRPIDFILE" ]; then
197 log_action_end_msg 1 "$QRNAME failed"
198 else
199 log_action_end_msg 0 "not running"
200 fi
201 fi
202 log_action_begin_msg "checking $SMTPNAME"
203 if pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
204 log_action_end_msg 0 "running"
205 exit 0
206 else
207 if [ -e "$PIDFILE" ]; then
208 log_action_end_msg 1 "$SMTPNAME failed"
209 exit 1
210 else
211 log_action_end_msg 0 "not running"
212 exit 3
213 fi
214 fi
215}
216
217# check for valid configuration file
218isconfigvalid()
219{
220if ! $DAEMON -bV > /dev/null ; then
221 log 1 "Warning! Invalid configuration file for $NAME. Exiting."
222 exit 1
223fi
224}
225
226# check for non-empty paniclog
227warn_paniclog()
228{
229 if [ -s "/var/log/exim4/paniclog" ]; then
230 if [ -z "$E4BCD_PANICLOG_NOISE" ] || grep -vq "$E4BCD_PANICLOG_NOISE" /var/log/exim4/paniclog; then
231 echo "ALERT: exim paniclog /var/log/exim4/paniclog has non-zero size, mail system possibly broken" 1>&2
232 fi
233 fi
234}
235
236case "$1" in
237 start)
238 log_daemon_msg "Starting MTA"
239 # regenerate exim4.conf
240 upex4conf
241 isconfigvalid
242 start_exim
243 log_end_msg 0
244 warn_paniclog
245 ;;
246 stop)
247 log_daemon_msg "Stopping MTA"
248 stop_exim
249 log_end_msg 0
250 warn_paniclog
251 ;;
252 restart)
0baa7b9d
SB
253 # check whether newly generated config would work
254 upex4conf --check
de45f55a 255 log_daemon_msg "Stopping MTA for restart"
0baa7b9d 256 stop_exim
de45f55a
AM
257 # regenerate exim4.conf
258 upex4conf
259 isconfigvalid
de45f55a
AM
260 log_end_msg 0
261 sleep 2
262 log_daemon_msg "Restarting MTA"
263 start_exim
264 log_end_msg 0
265 warn_paniclog
266 ;;
267 reload|force-reload)
268 log_daemon_msg "Reloading $NAME configuration files"
269 # regenerate exim4.conf
270 upex4conf
271 isconfigvalid
272 reload_exim
273 log_end_msg 0
274 warn_paniclog
275 ;;
276 status)
277 status
278 ;;
279 force-stop)
280 kill_all_exims $2
281 ;;
282 *)
0baa7b9d 283 echo "Usage: $0 {start|stop|restart|reload|status|force-stop}"
de45f55a
AM
284 exit 1
285 ;;
286esac
287
288exit 0
289# vim:tabstop=2:expandtab:shiftwidth=2