Merge branch 'debian'
[hcoop/debian/exim4.git] / debian / exim4-base.exim4.init
index 67a1059..61f2aff 100644 (file)
@@ -4,7 +4,7 @@
 # Written by Miquel van Smoorenburg <miquels@drinkel.ow.org>.
 # Modified for Debian GNU/Linux by Ian Murdock <imurdock@gnu.ai.mit.edu>.
 # Modified for exim by Tim Cutts <timc@chiark.greenend.org.uk>
-# Modified for exim4 by Andreas Metzler <ametzler@downhill.at.eu.org>
+# Modified for exim4 by Andreas Metzler <ametzler@debian.org>
 #                   and Marc Haber <mh+debian-packages@zugschlus.de>
 
 ### BEGIN INIT INFO
@@ -37,9 +37,9 @@ export LANG
 QUEUERUNNER='combined'
 QUEUEINTERVAL='30m'
 UPEX4OPTS=''
-PIDFILE="/var/run/exim4/exim.pid"
-QRPIDFILE="/var/run/exim4/eximqr.pid"
 [ -f /etc/default/exim4 ] && . /etc/default/exim4
+PIDFILE="/run/exim4/exim.pid"
+QRPIDFILE="/run/exim4/eximqr.pid"
 
 upex4conf() {
   UPEX4CONF="update-exim4.conf"
@@ -48,7 +48,7 @@ upex4conf() {
   for p in $PATH; do
     if [ -x "$p/$UPEX4CONF" ]; then
       IFS="$OLDIFS"
-      $p/$UPEX4CONF $UPEX4OPTS
+      $p/$UPEX4CONF $UPEX4OPTS $1
       return 0
     fi
   done
@@ -81,8 +81,8 @@ log()
 
 start_exim()
 {
-  [ -e /var/run/exim4 ] || \
-    install -d -oDebian-exim -gDebian-exim -m750 /var/run/exim4
+  [ -e /run/exim4 ] || \
+    install -d -oDebian-exim -gDebian-exim -m750 /run/exim4
   case ${QUEUERUNNER} in
     combined)
       start_daemon -p "$PIDFILE" \
@@ -106,8 +106,8 @@ start_exim()
       log_progress_msg "exim4_queuerunner"
       ;;
     queueonly)
-      start_daemon -p "$QRPIDFILE" \
-        "$DAEMON" -oP $QRPIDFILE \
+      start_daemon -p "$PIDFILE" \
+        "$DAEMON" -oP $PIDFILE \
         "-q${QFLAGS}${QUEUEINTERVAL}" \
         ${COMMONOPTIONS} \
         ${QUEUERUNNEROPTIONS}
@@ -130,15 +130,19 @@ stop_exim()
 # we try to kill eximqr and exim SMTP listener, no matter what
 # ${QUEUERUNNER} is set to, we could have switched since starting.
   if [ -f "$QRPIDFILE" ]; then
-    killproc -p "$QRPIDFILE" "$DAEMON"
+    start-stop-daemon --stop --retry 5 --quiet --oknodo --remove-pidfile \
+      --pidfile "$QRPIDFILE" \
+      --exec "$DAEMON"
     # exim does not remove the pidfile
-    if [ $? -eq 0 ] ; then rm -f "$QRPIDFILE" ; fi
+    if [ $? -eq 2 ] ; then rm -f "$QRPIDFILE" ; fi
     log_progress_msg "exim4_queuerunner"
   fi
   if [ -f "$PIDFILE" ]; then
-    killproc -p "$PIDFILE" "$DAEMON"
+    start-stop-daemon --stop --retry 5 --quiet --oknodo --remove-pidfile \
+      --pidfile "$PIDFILE" \
+      --exec "$DAEMON"
     # exim does not remove the pidfile
-    if [ $? -eq 0 ] ; then rm -f "$PIDFILE" ; fi
+    if [ $? -eq 2 ] ; then rm -f "$PIDFILE" ; fi
     log_progress_msg "exim4_listener"
   fi
 }
@@ -146,14 +150,20 @@ stop_exim()
 reload_exim()
 {
   case ${QUEUERUNNER} in
-    combined|no|ppp)
-      killproc -p "$PIDFILE" "$DAEMON" -HUP
+    combined|no|ppp|queueonly)
+      start-stop-daemon --stop --signal HUP --quiet --oknodo \
+        --pidfile "$PIDFILE" \
+        --exec "$DAEMON"
       log_progress_msg "exim4"
       ;;
     separate)
-      killproc -p "$PIDFILE" "$DAEMON" -HUP
+      start-stop-daemon --stop --signal HUP --quiet --oknodo \
+        --pidfile "$PIDFILE" \
+        --exec "$DAEMON"
       log_progress_msg "exim4_listener"
-      killproc -p "$QRPIDFILE" "$DAEMON" -HUP
+      start-stop-daemon --stop --signal HUP --quiet --oknodo \
+        --pidfile "$QRPIDFILE" \
+        --exec "$DAEMON"
       log_progress_msg "exim4_queuerunner"
       ;;
   esac
@@ -176,6 +186,8 @@ status()
   QRNAME="separate queue runner daemon"
   if [ "${QUEUERUNNER}" = "combined" ]; then
       SMTPNAME="combined SMTP listener and queue runner daemon"
+  elif [ "${QUEUERUNNER}" = "queueonly" ]; then
+    SMTPNAME="separate queue runner daemon"
   fi
   log_action_begin_msg "checking $QRNAME"
   if pidofproc -p "$QRPIDFILE" "$DAEMON" >/dev/null; then
@@ -238,11 +250,13 @@ case "$1" in
     warn_paniclog
     ;;
   restart)
+    # check whether newly generated config would work
+    upex4conf --check
     log_daemon_msg "Stopping MTA for restart"
+    stop_exim
     # regenerate exim4.conf
     upex4conf
     isconfigvalid
-    stop_exim
     log_end_msg 0
     sleep 2
     log_daemon_msg "Restarting MTA"
@@ -266,7 +280,7 @@ case "$1" in
     kill_all_exims $2
     ;;
   *)
-    echo "Usage: $0 {start|stop|restart|reload|status|what|force-stop}"
+    echo "Usage: $0 {start|stop|restart|reload|status|force-stop}"
     exit 1
     ;;
 esac