Relax chown requirements when check_owner is false
[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@downhill.at.eu.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 PIDFILE="/var/run/exim4/exim.pid"
41 QRPIDFILE="/var/run/exim4/eximqr.pid"
42 [ -f /etc/default/exim4 ] && . /etc/default/exim4
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
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 /var/run/exim4 ] || \
85 install -d -oDebian-exim -gDebian-exim -m750 /var/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 "$QRPIDFILE" \
110 "$DAEMON" -oP $QRPIDFILE \
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)
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 fi
180 log_action_begin_msg "checking $QRNAME"
181 if pidofproc -p "$QRPIDFILE" "$DAEMON" >/dev/null; then
182 log_action_end_msg 0 "running"
183 else
184 if [ -e "$QRPIDFILE" ]; then
185 log_action_end_msg 1 "$QRNAME failed"
186 else
187 log_action_end_msg 0 "not running"
188 fi
189 fi
190 log_action_begin_msg "checking $SMTPNAME"
191 if pidofproc -p "$PIDFILE" "$DAEMON" >/dev/null; then
192 log_action_end_msg 0 "running"
193 exit 0
194 else
195 if [ -e "$PIDFILE" ]; then
196 log_action_end_msg 1 "$SMTPNAME failed"
197 exit 1
198 else
199 log_action_end_msg 0 "not running"
200 exit 3
201 fi
202 fi
203 }
204
205 # check for valid configuration file
206 isconfigvalid()
207 {
208 if ! $DAEMON -bV > /dev/null ; then
209 log 1 "Warning! Invalid configuration file for $NAME. Exiting."
210 exit 1
211 fi
212 }
213
214 # check for non-empty paniclog
215 warn_paniclog()
216 {
217 if [ -s "/var/log/exim4/paniclog" ]; then
218 if [ -z "$E4BCD_PANICLOG_NOISE" ] || grep -vq "$E4BCD_PANICLOG_NOISE" /var/log/exim4/paniclog; then
219 echo "ALERT: exim paniclog /var/log/exim4/paniclog has non-zero size, mail system possibly broken" 1>&2
220 fi
221 fi
222 }
223
224 case "$1" in
225 start)
226 log_daemon_msg "Starting MTA"
227 # regenerate exim4.conf
228 upex4conf
229 isconfigvalid
230 start_exim
231 log_end_msg 0
232 warn_paniclog
233 ;;
234 stop)
235 log_daemon_msg "Stopping MTA"
236 stop_exim
237 log_end_msg 0
238 warn_paniclog
239 ;;
240 restart)
241 log_daemon_msg "Stopping MTA for restart"
242 # regenerate exim4.conf
243 upex4conf
244 isconfigvalid
245 stop_exim
246 log_end_msg 0
247 sleep 2
248 log_daemon_msg "Restarting MTA"
249 start_exim
250 log_end_msg 0
251 warn_paniclog
252 ;;
253 reload|force-reload)
254 log_daemon_msg "Reloading $NAME configuration files"
255 # regenerate exim4.conf
256 upex4conf
257 isconfigvalid
258 reload_exim
259 log_end_msg 0
260 warn_paniclog
261 ;;
262 status)
263 status
264 ;;
265 force-stop)
266 kill_all_exims $2
267 ;;
268 *)
269 echo "Usage: $0 {start|stop|restart|reload|status|what|force-stop}"
270 exit 1
271 ;;
272 esac
273
274 exit 0
275 # vim:tabstop=2:expandtab:shiftwidth=2