Import Debian changes 4.89-2+deb9u3~bpo8+1
[hcoop/debian/exim4.git] / debian / exim4-base.exim4.init
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>
7 # Modified for exim4 by Andreas Metzler <ametzler@debian.org>
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
22 set -e
23
24 test -x /usr/lib/exim4/exim4 || exit 0
25
26 . /lib/lsb/init-functions
27
28 if [ -n "$EX4DEBUG" ]; then
29 echo "now debugging $0 $@"
30 set -x
31 fi
32
33 LANG=C
34 export LANG
35
36 #read default file
37 QUEUERUNNER='combined'
38 QUEUEINTERVAL='30m'
39 UPEX4OPTS=''
40 [ -f /etc/default/exim4 ] && . /etc/default/exim4
41 PIDFILE="/run/exim4/exim.pid"
42 QRPIDFILE="/run/exim4/eximqr.pid"
43
44 upex4conf() {
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"
51 $p/$UPEX4CONF $UPEX4OPTS $1
52 return 0
53 fi
54 done
55 IFS="$OLDIFS"
56 }
57
58 # Exit if exim runs from /etc/inetd.conf
59 if [ -f /etc/inetd.conf ] && grep -E -q '^[[:space:]]*((\*|[[:alnum:].-]+):)?smtp[[:space:]]' /etc/inetd.conf
60 then
61 upex4conf
62 exit 0
63 fi
64
65
66 DAEMON="/usr/sbin/exim4"
67 NAME="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
72 log()
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
82 start_exim()
83 {
84 [ -e /run/exim4 ] || \
85 install -d -oDebian-exim -gDebian-exim -m750 /run/exim4
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)
109 start_daemon -p "$PIDFILE" \
110 "$DAEMON" -oP $PIDFILE \
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
128 stop_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
133 killproc -p "$QRPIDFILE" "$DAEMON"
134 # exim does not remove the pidfile
135 if [ $? -eq 0 ] ; then rm -f "$QRPIDFILE" ; fi
136 log_progress_msg "exim4_queuerunner"
137 fi
138 if [ -f "$PIDFILE" ]; then
139 killproc -p "$PIDFILE" "$DAEMON"
140 # exim does not remove the pidfile
141 if [ $? -eq 0 ] ; then rm -f "$PIDFILE" ; fi
142 log_progress_msg "exim4_listener"
143 fi
144 }
145
146 reload_exim()
147 {
148 case ${QUEUERUNNER} in
149 combined|no|ppp|queueonly)
150 killproc -p "$PIDFILE" "$DAEMON" -HUP
151 log_progress_msg "exim4"
152 ;;
153 separate)
154 killproc -p "$PIDFILE" "$DAEMON" -HUP
155 log_progress_msg "exim4_listener"
156 killproc -p "$QRPIDFILE" "$DAEMON" -HUP
157 log_progress_msg "exim4_queuerunner"
158 ;;
159 esac
160 }
161
162 kill_all_exims()
163 { SIG="${1:-TERM}"
164 for pid in $(pidof $NAME); do
165 if [ "$(readlink /proc/$pid/root)" = "/" ]; then
166 kill -$SIG $pid
167 fi
168 done
169 }
170
171 status()
172 {
173 # the exit value of this function reflects the status of the SMTP
174 # service. Output shows the status of the queue runner as well.
175 SMTPNAME="SMTP listener daemon"
176 QRNAME="separate queue runner daemon"
177 if [ "${QUEUERUNNER}" = "combined" ]; then
178 SMTPNAME="combined SMTP listener and queue runner daemon"
179 elif [ "${QUEUERUNNER}" = "queueonly" ]; then
180 SMTPNAME="separate queue runner daemon"
181 fi
182 log_action_begin_msg "checking $QRNAME"
183 if pidofproc -p "$QRPIDFILE" "$DAEMON" >/dev/null; then
184 log_action_end_msg 0 "running"
185 else
186 if [ -e "$QRPIDFILE" ]; then
187 log_action_end_msg 1 "$QRNAME failed"
188 else
189 log_action_end_msg 0 "not running"
190 fi
191 fi
192 log_action_begin_msg "checking $SMTPNAME"
193 if pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
194 log_action_end_msg 0 "running"
195 exit 0
196 else
197 if [ -e "$PIDFILE" ]; then
198 log_action_end_msg 1 "$SMTPNAME failed"
199 exit 1
200 else
201 log_action_end_msg 0 "not running"
202 exit 3
203 fi
204 fi
205 }
206
207 # check for valid configuration file
208 isconfigvalid()
209 {
210 if ! $DAEMON -bV > /dev/null ; then
211 log 1 "Warning! Invalid configuration file for $NAME. Exiting."
212 exit 1
213 fi
214 }
215
216 # check for non-empty paniclog
217 warn_paniclog()
218 {
219 if [ -s "/var/log/exim4/paniclog" ]; then
220 if [ -z "$E4BCD_PANICLOG_NOISE" ] || grep -vq "$E4BCD_PANICLOG_NOISE" /var/log/exim4/paniclog; then
221 echo "ALERT: exim paniclog /var/log/exim4/paniclog has non-zero size, mail system possibly broken" 1>&2
222 fi
223 fi
224 }
225
226 case "$1" in
227 start)
228 log_daemon_msg "Starting MTA"
229 # regenerate exim4.conf
230 upex4conf
231 isconfigvalid
232 start_exim
233 log_end_msg 0
234 warn_paniclog
235 ;;
236 stop)
237 log_daemon_msg "Stopping MTA"
238 stop_exim
239 log_end_msg 0
240 warn_paniclog
241 ;;
242 restart)
243 # check whether newly generated config would work
244 upex4conf --check
245 log_daemon_msg "Stopping MTA for restart"
246 stop_exim
247 # regenerate exim4.conf
248 upex4conf
249 isconfigvalid
250 log_end_msg 0
251 sleep 2
252 log_daemon_msg "Restarting MTA"
253 start_exim
254 log_end_msg 0
255 warn_paniclog
256 ;;
257 reload|force-reload)
258 log_daemon_msg "Reloading $NAME configuration files"
259 # regenerate exim4.conf
260 upex4conf
261 isconfigvalid
262 reload_exim
263 log_end_msg 0
264 warn_paniclog
265 ;;
266 status)
267 status
268 ;;
269 force-stop)
270 kill_all_exims $2
271 ;;
272 *)
273 echo "Usage: $0 {start|stop|restart|reload|status|force-stop}"
274 exit 1
275 ;;
276 esac
277
278 exit 0
279 # vim:tabstop=2:expandtab:shiftwidth=2